Added FisheryLib.Collections.FishTable and Mono.Cecil extension methods
A bit of refactoring has been done too
This commit is contained in:
@@ -52,9 +52,7 @@ public static class TypeExtensions
|
||||
{
|
||||
// Primitive types use the keyword name
|
||||
if (BuiltInTypesMap.TryGetValue(type, out var typeName))
|
||||
{
|
||||
return typeName!;
|
||||
}
|
||||
|
||||
// Array types are displayed as Foo[]
|
||||
if (type.IsArray)
|
||||
@@ -62,7 +60,8 @@ public static class TypeExtensions
|
||||
var elementType = type.GetElementType()!;
|
||||
var rank = type.GetArrayRank();
|
||||
|
||||
return $"{FormatDisplayString(elementType, 0, elementType.GetGenericArguments())}[{new string(',', rank - 1)}]";
|
||||
return $"{FormatDisplayString(elementType, 0,
|
||||
elementType.GetGenericArguments())}[{new string(',', rank - 1)}]";
|
||||
}
|
||||
|
||||
// By checking generic types here we are only interested in specific cases,
|
||||
@@ -84,16 +83,17 @@ public static class TypeExtensions
|
||||
}
|
||||
|
||||
// ValueTuple<T1, T2> types are displayed as (T1, T2)
|
||||
if (genericTypeDefinition == typeof(ValueTuple<>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,,>) ||
|
||||
genericTypeDefinition == typeof(ValueTuple<,,,,,,,>))
|
||||
if (genericTypeDefinition == typeof(ValueTuple<>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,,>)
|
||||
|| genericTypeDefinition == typeof(ValueTuple<,,,,,,,>))
|
||||
{
|
||||
var formattedTypes = type.GetGenericArguments().Select(t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
var formattedTypes = type.GetGenericArguments()
|
||||
.Select(static t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
|
||||
return $"({string.Join(", ", formattedTypes)})";
|
||||
}
|
||||
@@ -109,7 +109,8 @@ public static class TypeExtensions
|
||||
var genericArgumentsCount = int.Parse(tokens[1]);
|
||||
var typeArgumentsOffset = typeArguments.Length - genericTypeOffset - genericArgumentsCount;
|
||||
var currentTypeArguments = typeArguments.Slice(typeArgumentsOffset, genericArgumentsCount).ToArray();
|
||||
var formattedTypes = currentTypeArguments.Select(t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
var formattedTypes
|
||||
= currentTypeArguments.Select(static t => FormatDisplayString(t, 0, t.GetGenericArguments()));
|
||||
|
||||
// Standard generic types are displayed as Foo<T>
|
||||
displayName = $"{tokens[0]}<{string.Join(", ", formattedTypes)}>";
|
||||
@@ -130,7 +131,7 @@ public static class TypeExtensions
|
||||
}
|
||||
|
||||
// Atomically get or build the display string for the current type.
|
||||
return DisplayNames.GetValue(type, t =>
|
||||
return DisplayNames.GetValue(type, static t =>
|
||||
{
|
||||
// By-ref types are displayed as T&
|
||||
if (t.IsByRef)
|
||||
@@ -159,4 +160,4 @@ public static class TypeExtensions
|
||||
return FormatDisplayString(t, 0, t.GetGenericArguments());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,8 @@ public static class ValueTypeExtensions
|
||||
/// <summary>
|
||||
/// Gets the table of hex characters (doesn't allocate, maps to .text section, see <see href="https://github.com/dotnet/roslyn/pull/24621"/>).
|
||||
/// </summary>
|
||||
private static ReadOnlySpan<byte> HexCharactersTable => new[]
|
||||
{
|
||||
(byte)'0', (byte)'1', (byte)'2', (byte)'3',
|
||||
(byte)'4', (byte)'5', (byte)'6', (byte)'7',
|
||||
(byte)'8', (byte)'9', (byte)'A', (byte)'B',
|
||||
(byte)'C', (byte)'D', (byte)'E', (byte)'F'
|
||||
};
|
||||
private static ReadOnlySpan<byte> HexCharactersTable
|
||||
=> "0123456789ABCDEF"u8;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hexadecimal <see cref="string"/> representation of a given <typeparamref name="T"/> value, left-padded and ordered as big-endian.
|
||||
@@ -42,7 +37,7 @@ public static class ValueTypeExtensions
|
||||
public static unsafe string ToHexString<T>(this T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
var sizeOfT = Unsafe.SizeOf<T>();
|
||||
var sizeOfT = sizeof(T);
|
||||
var bufferSize = (2 * sizeOfT) + 2;
|
||||
var p = stackalloc char[bufferSize];
|
||||
|
||||
@@ -63,4 +58,4 @@ public static class ValueTypeExtensions
|
||||
|
||||
return new(p, 0, bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user