7 instantiations of TypeName
System.Reflection.Metadata (7)
System\Reflection\Metadata\TypeName.cs (3)
608
return new
TypeName
(fullName: _fullName,
673
return new
TypeName
(fullName: null, AssemblyName, elementOrGenericType: this, declaringType: _declaringType, genericTypeArguments: typeArguments);
677
=> new
TypeName
(
System\Reflection\Metadata\TypeNameParser.cs (4)
207
TypeName result =
new
(fullName, assemblyName, declaringType: declaringType);
210
result =
new
(fullName: null, assemblyName, elementOrGenericType: result, declaringType, genericArgs);
220
result =
new
(fullName: null, assemblyName, elementOrGenericType: result, rankOrModifier: parsedModifier);
267
declaringType =
new
(fullTypeName, assemblyName, declaringType: declaringType, nestedNameLength: fullNameLength);
440 references to TypeName
illink (12)
Linker\TypeNameResolver.cs (7)
9
using TypeName = System.Reflection.Metadata.
TypeName
;
40
if (!
TypeName
.TryParse (typeNameString, out
TypeName
? parsedTypeName, s_typeNameParseOptions)) {
52
TypeReference? ResolveTypeName (AssemblyDefinition originalAssembly,
TypeName
? typeName, List<TypeResolutionRecord> typeResolutionRecords)
72
foreach (
var
arg in typeName.GetGenericArguments()) {
97
TypeName
topLevelTypeName = typeName;
125
TypeDefinition? GetSimpleTypeFromModule (
TypeName
typeName, ModuleDefinition module)
Linker\TypeNameResolver.WithDiagnostics.cs (5)
11
using TypeName = System.Reflection.Metadata.
TypeName
;
29
if (!
TypeName
.TryParse (typeNameString, out
TypeName
? parsedTypeName, s_typeNameParseOptions))
56
static bool IsFullyQualified (
TypeName
typeName)
65
foreach (
var
typeArgument in typeName.GetGenericArguments ()) {
Microsoft.VisualBasic.Forms (2)
Microsoft\VisualBasic\MyServices\ClipboardProxy.vb (2)
196
''' <inheritdoc cref="Clipboard.TryGetData(Of T)(String, Func(Of
TypeName
, Type), ByRef T)" />
197
Public Function TryGetData(Of T)(format As String, resolver As Func(Of
TypeName
, Type), <Out> ByRef data As T) As Boolean
Microsoft.VisualBasic.Tests (1)
Microsoft\VisualBasic\MyServices\ClipboardProxyTests.cs (1)
154
public static Type Resolver(
TypeName
typeName) =>
System.Formats.Nrbf (61)
System\Formats\Nrbf\ArrayRectangularPrimitiveRecord.cs (2)
22
private
TypeName
? _typeName;
35
public override
TypeName
TypeName
System\Formats\Nrbf\ArraySingleObjectRecord.cs (1)
24
public override
TypeName
TypeName
System\Formats\Nrbf\ArraySinglePrimitiveRecord.cs (1)
36
public override
TypeName
TypeName => TypeNameHelpers.GetPrimitiveSZArrayTypeName(TypeNameHelpers.GetPrimitiveType<T>());
System\Formats\Nrbf\ArraySingleStringRecord.cs (1)
25
public override
TypeName
TypeName => TypeNameHelpers.GetPrimitiveSZArrayTypeName(TypeNameHelpers.StringPrimitiveType);
System\Formats\Nrbf\BinaryLibraryRecord.cs (2)
33
public override
TypeName
TypeName =>
TypeName
.Parse(nameof(BinaryLibraryRecord).AsSpan());
System\Formats\Nrbf\ClassInfo.cs (2)
23
private
TypeName
? _typeName;
34
internal
TypeName
TypeName
System\Formats\Nrbf\ClassRecord.cs (1)
23
public override
TypeName
TypeName => ClassInfo.TypeName;
System\Formats\Nrbf\ClassTypeInfo.cs (2)
20
internal ClassTypeInfo(
TypeName
typeName) => TypeName = typeName;
22
internal
TypeName
TypeName { get; }
System\Formats\Nrbf\JaggedArrayRecord.cs (2)
26
private
TypeName
? _typeName;
43
public override
TypeName
TypeName => _typeName ??= _memberTypeInfo.GetArrayTypeName(ArrayInfo);
System\Formats\Nrbf\MemberReferenceRecord.cs (1)
34
public override
TypeName
TypeName => GetReferencedRecord().TypeName;
System\Formats\Nrbf\MemberTypeInfo.cs (3)
111
internal
TypeName
GetArrayTypeName(ArrayInfo arrayInfo)
115
TypeName
elementTypeName = binaryType switch
123
BinaryType.SystemClass => (
TypeName
)additionalInfo!,
System\Formats\Nrbf\MessageEndRecord.cs (2)
27
public override
TypeName
TypeName =>
TypeName
.Parse(nameof(MessageEndRecord).AsSpan());
System\Formats\Nrbf\NrbfDecoder.cs (5)
402
TypeName
typeName = binaryType == BinaryType.SystemClass ? (
TypeName
)additionalInfo! : ((ClassTypeInfo)additionalInfo!).TypeName;
418
TypeName
typeName = binaryType == BinaryType.SystemClass ? (
TypeName
)additionalInfo! : ((ClassTypeInfo)additionalInfo!).TypeName;
452
else if (binaryType == BinaryType.SystemClass && ((
TypeName
)additionalInfo!).IsArray)
System\Formats\Nrbf\NullsRecord.cs (2)
15
public override
TypeName
TypeName =>
TypeName
.Parse(GetType().Name.AsSpan());
System\Formats\Nrbf\PayloadOptions.cs (1)
19
/// Gets or sets configuration options for parsing <see cref="
TypeName
"/> instances.
System\Formats\Nrbf\PrimitiveTypeRecordOfT.cs (1)
37
public override
TypeName
TypeName => TypeNameHelpers.GetPrimitiveTypeName(TypeNameHelpers.GetPrimitiveType<T>());
System\Formats\Nrbf\RectangularArrayRecord.cs (2)
23
private
TypeName
? _typeName;
41
public override
TypeName
TypeName
System\Formats\Nrbf\SerializationRecord.cs (3)
46
public abstract
TypeName
TypeName { get; }
72
private static bool Matches(Type type,
TypeName
typeName)
132
ImmutableArray<
TypeName
> genericNames = typeName.GetGenericArguments();
System\Formats\Nrbf\SerializedStreamHeaderRecord.cs (2)
27
public override
TypeName
TypeName =>
TypeName
.Parse(nameof(SerializedStreamHeaderRecord).AsSpan());
System\Formats\Nrbf\SystemClassWithMembersAndTypesRecord.cs (1)
31
TypeName
typeName = classInfo.TypeName;
System\Formats\Nrbf\SZArrayOfRecords.cs (2)
17
private
TypeName
? _typeName;
32
public override
TypeName
TypeName
System\Formats\Nrbf\Utils\TypeNameHelpers.cs (22)
20
private static readonly
TypeName
?[] s_primitiveTypeNames = new
TypeName
?[(int)UIntPtrPrimitiveType + 1];
21
private static readonly
TypeName
?[] s_primitiveSZArrayTypeNames = new
TypeName
?[(int)UIntPtrPrimitiveType + 1];
24
internal static
TypeName
GetPrimitiveTypeName(PrimitiveType primitiveType)
26
TypeName
? typeName = s_primitiveTypeNames[(int)primitiveType];
53
s_primitiveTypeNames[(int)primitiveType] = typeName =
TypeName
.Parse(fullName.AsSpan()).WithCoreLibAssemblyName();
58
internal static
TypeName
GetPrimitiveSZArrayTypeName(PrimitiveType primitiveType)
60
TypeName
? typeName = s_primitiveSZArrayTypeNames[(int)primitiveType];
110
internal static
TypeName
ParseNonSystemClassRecordTypeName(this string rawName, BinaryLibraryRecord libraryRecord, PayloadOptions payloadOptions)
133
TypeName
.TryParse(assemblyQualifiedName.AsSpan(), out
TypeName
? typeName, payloadOptions.TypeNameParseOptions);
153
internal static
TypeName
ParseSystemRecordTypeName(this string rawName, PayloadOptions payloadOptions)
157
internal static
TypeName
WithCoreLibAssemblyName(this
TypeName
systemType)
160
private static
TypeName
With(this
TypeName
typeName, AssemblyNameInfo assemblyName)
170
TypeName
newElementType = typeName.GetElementType().With(assemblyName);
178
TypeName
newGenericTypeDefinition = typeName.GetGenericTypeDefinition().With(assemblyName);
193
private static
TypeName
ParseWithoutAssemblyName(string rawName, PayloadOptions payloadOptions)
195
if (!
TypeName
.TryParse(rawName.AsSpan(), out
TypeName
? typeName, payloadOptions.TypeNameParseOptions)
System.Private.Windows.Core (72)
System\Private\Windows\BinaryFormat\Deserializer\DefaultTypeResolver.cs (3)
24
Type ITypeResolver.BindToType(
TypeName
typeName)
34
public bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
90
private static Type? GetSimplyNamedTypeFromAssembly(Assembly assembly,
TypeName
typeName)
System\Private\Windows\BinaryFormat\ITypeResolver.cs (2)
16
Type BindToType(
TypeName
typeName);
21
bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type);
System\Private\Windows\Nrbf\CoreNrbfSerializer.cs (21)
17
private static Dictionary<
TypeName
, Type>? s_knownTypes;
29
public static bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
36
{
TypeName
.Parse(Types.ByteType), typeof(byte) },
37
{
TypeName
.Parse(Types.SByteType), typeof(sbyte) },
38
{
TypeName
.Parse(Types.Int16Type), typeof(short) },
39
{
TypeName
.Parse(Types.UInt16Type), typeof(ushort) },
40
{
TypeName
.Parse(Types.Int32Type), typeof(int) },
41
{
TypeName
.Parse(Types.UInt32Type), typeof(uint) },
42
{
TypeName
.Parse(Types.Int64Type), typeof(long) },
43
{
TypeName
.Parse(Types.UInt64Type), typeof(ulong) },
44
{
TypeName
.Parse(Types.DoubleType), typeof(double) },
45
{
TypeName
.Parse(Types.SingleType), typeof(float) },
46
{
TypeName
.Parse(Types.CharType), typeof(char) },
47
{
TypeName
.Parse(Types.BooleanType), typeof(bool) },
48
{
TypeName
.Parse(Types.StringType), typeof(string) },
49
{
TypeName
.Parse(Types.DecimalType), typeof(decimal) },
50
{
TypeName
.Parse(Types.DateTimeType), typeof(DateTime) },
51
{
TypeName
.Parse(Types.TimeSpanType), typeof(TimeSpan) },
52
{
TypeName
.Parse(Types.IntPtrType), typeof(IntPtr) },
53
{
TypeName
.Parse(Types.UIntPtrType), typeof(UIntPtr) },
54
{
TypeName
.Parse(Types.NotSupportedExceptionType), typeof(NotSupportedException) },
System\Private\Windows\Nrbf\INrbfSerializer.cs (2)
25
static abstract bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type);
38
/// <see cref="TryBindToType(
TypeName
, out Type?)"/> and <see cref="TryGetObject(SerializationRecord, out object?)"/>
System\Private\Windows\Nrbf\SerializationRecordExtensions.cs (2)
604
|| !
TypeName
.TryParse(assemblyQualifiedTypeName, out
TypeName
? typeName))
System\Private\Windows\Ole\Composition.cs (1)
159
Func<
TypeName
, Type?> resolver,
System\Private\Windows\Ole\Composition.NativeToManagedAdapter.cs (1)
591
Func<
TypeName
, Type?> resolver,
System\Private\Windows\Ole\DataRequest.cs (2)
28
/// <see cref="
TypeName
"/>s read from the deserialized stream.
30
public Func<
TypeName
, Type?>? Resolver { get; init; } = null;
System\Private\Windows\Ole\DataStore.cs (1)
178
Func<
TypeName
, Type?> resolver,
System\Private\Windows\Ole\IDataObjectInternal.cs (5)
96
/// <inheritdoc cref="TryGetData{T}(string, Func{
TypeName
, Type}, bool, out T)"/>
103
/// <inheritdoc cref="TryGetData{T}(string, Func{
TypeName
, Type}, bool, out T)"/>
112
/// <inheritdoc cref="TryGetData{T}(string, Func{
TypeName
, Type}, bool, out T)"/>
122
/// A user-provided function that maps <see cref="
TypeName
"/> to <see cref="Type"/>.
151
Func<
TypeName
, Type?> resolver,
System\Private\Windows\Ole\TypeBinder.cs (6)
35
private readonly Func<
TypeName
, Type?>? _resolver;
38
private Dictionary<FullyQualifiedTypeName,
TypeName
>? _cachedTypeNames;
79
if (!_cachedTypeNames.TryGetValue(fullName, out
TypeName
? parsed))
81
parsed =
TypeName
.Parse(fullName.ToString());
88
public Type BindToType(
TypeName
typeName) => TryBindToType(typeName, out Type? type)
94
public bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
System\Reflection\Metadata\TypeNameComparer.cs (6)
7
/// Compares <see cref="
TypeName
"/>s.
9
internal sealed class TypeNameComparer : IEqualityComparer<
TypeName
>
32
public bool Equals(
TypeName
? x,
TypeName
? y)
47
public int GetHashCode(
TypeName
obj)
63
foreach (
TypeName
genericName in obj.GetGenericArguments())
System\TypeExtensions.cs (16)
12
/// Helper methods for comparing <see cref="Type"/>s and <see cref="
TypeName
"/>s.
24
TypeName
typeName,
71
ImmutableArray<
TypeName
> genericNames = typeName.GetGenericArguments();
96
/// <inheritdoc cref="Matches(Type,
TypeName
, TypeNameComparison)"/>
97
internal static bool Matches(this
TypeName
x,
TypeName
y, TypeNameComparison comparison = TypeNameComparison.All)
131
ImmutableArray<
TypeName
> genericNamesY = y.GetGenericArguments();
132
ImmutableArray<
TypeName
> genericNamesX = x.GetGenericArguments();
218
/// Convert <paramref name="type"/> to <see cref="
TypeName
"/>. Take into account type forwarding in order
219
/// to create <see cref="
TypeName
"/> compatible with the type names serialized to the binary format.This
220
/// method removes nullability wrapper from the top level type only because <see cref="
TypeName
"/> in the
223
internal static
TypeName
ToTypeName(this Type type)
227
return
TypeName
.Parse(type.AssemblyQualifiedName ?? type.FullName);
239
/// Helper method that allows non-allocating conversion of a interpolated string to a <see cref="
TypeName
"/>.
241
internal static
TypeName
ToTypeName(ref ValueStringBuilder builder)
245
return
TypeName
.Parse(builder.AsSpan());
System\Types.cs (4)
49
/// <inheritdoc cref="
TypeName
.Parse(ReadOnlySpan{char}, TypeNameParseOptions?)"/>
53
/// <see cref="
TypeName
.Parse(ReadOnlySpan{char}, TypeNameParseOptions?)"/>
56
public static
TypeName
ToTypeName(ref ValueStringBuilder builder)
60
return
TypeName
.Parse(builder.AsSpan());
System.Private.Windows.Core.Tests (177)
System\Private\Windows\Nrbf\CoreNrbfSerializerTests.cs (2)
79
TypeName
typeName =
TypeName
.Parse(typeNameString);
System\Private\Windows\Ole\BinaryFormatUtilitesTestsBase.cs (6)
46
Func<
TypeName
, Type>? resolver,
64
protected bool ReadObjectFromStream<T>(bool restrictDeserialization, Func<
TypeName
, Type>? resolver, out T? @object)
76
protected bool TryReadObjectFromStream<T>(Func<
TypeName
, Type>? resolver, out T? @object)
82
protected bool ReadPredefinedObjectFromStream<T>(Func<
TypeName
, Type>? resolver, out T? @object)
119
protected bool RoundTripOfType<T>(object value, Func<
TypeName
, Type>? resolver, out T? @object)
127
protected static Type NotSupportedResolver(
TypeName
typeName) =>
System\Private\Windows\Ole\BinaryFormatUtilitiesTests.cs (16)
23
Func<
TypeName
, Type>? resolver,
241
Resolver = (
TypeName
typeName) => Type.GetType(typeName.FullName)
299
Resolver = (
TypeName
typeName) => typeof(int[]).Matches(typeName, TypeNameComparison.TypeFullName)
429
static Type ObjectListResolver(
TypeName
typeName)
493
Resolver = (
TypeName
typeName) => typeName.FullName == typeof(DerivedClass).FullName
532
Resolver = (
TypeName
typeName) => typeName.FullName == typeof(MyStruct).FullName
581
Resolver = (
TypeName
typeName) => typeName.FullName == typeof(int).FullName
620
Resolver = (
TypeName
typeName) => typeName.FullName == typeof(int).FullName
708
private static Type NullableIntArrayResolver(
TypeName
typeName)
738
static Type TestDataResolver(
TypeName
typeName)
780
static Type InvalidResolver(
TypeName
typeName) => null!;
847
Resolver = (
TypeName
typeName) =>
1089
internal static Type MyExactMatchResolver(
TypeName
typeName)
1092
(Type type,
TypeName
typeName)[] allowedTypes =
1094
(typeof(MyClass1),
TypeName
.Parse(typeof(MyClass1).AssemblyQualifiedName)),
1095
(typeof(MyClass2),
TypeName
.Parse(typeof(MyClass2).AssemblyQualifiedName))
System\Private\Windows\Ole\TestDataObject.cs (2)
89
Func<
TypeName
, Type?> resolver,
96
Func<
TypeName
, Type?>? resolver,
System\Private\Windows\Ole\TestDataObjectAdapter.cs (1)
44
Func<
TypeName
, Type?> resolver,
System\Private\Windows\Ole\TypeBinderTests.cs (16)
61
TypeName
typeName =
TypeName
.Parse(type.AssemblyQualifiedName);
80
Resolver = (
TypeName
typeName) => typeof(MyClass).Matches(typeName) ? typeof(MyClass) : null
87
TypeName
typeName =
TypeName
.Parse(type.AssemblyQualifiedName);
104
TypeName
typeName =
TypeName
.Parse(type.AssemblyQualifiedName);
118
Resolver = (
TypeName
typeName) => typeof(MyClass)
123
binder.TryBindToType(
TypeName
.Parse(typeof(int).AssemblyQualifiedName), out Type? boundType).Should().Be(true);
133
Resolver = (
TypeName
typeName) => throw new NotSupportedException()
138
binder.TryBindToType(
TypeName
.Parse(typeof(int).AssemblyQualifiedName), out Type? boundType).Should().Be(false);
148
Resolver = (
TypeName
typeName) => null!
153
binder.TryBindToType(
TypeName
.Parse(typeof(int).AssemblyQualifiedName), out Type? boundType).Should().Be(true);
161
public static bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
182
public static bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
204
public static bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
System\Reflection\Metadata\TypeNameComparerTests.cs (89)
10
public static TheoryData<
TypeName
, Type> TypeNameComparer_FullyQualified_Success() => new()
12
{
TypeName
.Parse(typeof(int).AssemblyQualifiedName), typeof(int) },
13
{
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.FullName}"), typeof(int) },
14
{
TypeName
.Parse(typeof(int[]).AssemblyQualifiedName), typeof(int[]) },
15
{
TypeName
.Parse($"{typeof(int[]).FullName}, {typeof(int[]).Assembly.FullName}"), typeof(int[]) },
16
{
TypeName
.Parse(typeof(List<int>).AssemblyQualifiedName), typeof(List<int>) },
17
{
TypeName
.Parse($"{typeof(List<int>).FullName}, {typeof(List<int>).Assembly.FullName}"), typeof(List<int>) },
18
{
TypeName
.Parse(typeof(TestType).AssemblyQualifiedName), typeof(TestType) },
19
{
TypeName
.Parse($"{typeof(TestType).FullName}, {typeof(TestType).Assembly.FullName}"), typeof(TestType) },
24
public void DictionaryLookup_FullyQualified_Succeeds(
TypeName
name, Type expected)
26
Dictionary<
TypeName
, Type> types = new(TypeNameComparer.FullyQualifiedMatch)
28
{
TypeName
.Parse(typeof(int).AssemblyQualifiedName), typeof(int) },
29
{
TypeName
.Parse(typeof(int[]).AssemblyQualifiedName), typeof(int[]) },
30
{
TypeName
.Parse(typeof(List<int>).AssemblyQualifiedName), typeof(List<int>) },
31
{
TypeName
.Parse(typeof(TestType).AssemblyQualifiedName), typeof(TestType) },
38
public static TheoryData<
TypeName
> TypeNameComparer_FullyQualified_Fail() =>
40
TypeName
.Parse("System.Int32[], System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"),
41
TypeName
.Parse("System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"),
42
TypeName
.Parse("System.Int32, System.Private.CoreLib, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"),
43
TypeName
.Parse($"System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], {typeof(List<int>).Assembly.FullName}"),
44
TypeName
.Parse($"{typeof(TestType).FullName}, {typeof(int).Assembly.FullName}")
51
public void DictionaryLookup_FullyQualified_VersionMismatch(
TypeName
name)
53
Dictionary<
TypeName
, Type> types = new(TypeNameComparer.FullyQualifiedMatch)
55
{
TypeName
.Parse(typeof(int).AssemblyQualifiedName), typeof(int) },
56
{
TypeName
.Parse(typeof(int[]).AssemblyQualifiedName), typeof(int[]) },
57
{
TypeName
.Parse(typeof(List<int>).AssemblyQualifiedName), typeof(List<int>) },
58
{
TypeName
.Parse(typeof(TestType).AssemblyQualifiedName), typeof(TestType) },
67
Dictionary<
TypeName
, Type> types = new(TypeNameComparer.FullyQualifiedMatch)
69
{
TypeName
.Parse(typeof(int).AssemblyQualifiedName), typeof(int) },
70
{
TypeName
.Parse(typeof(int[]).AssemblyQualifiedName), typeof(int[]) },
71
{
TypeName
.Parse(typeof(List<int>).AssemblyQualifiedName), typeof(List<int>) },
72
{
TypeName
.Parse(typeof(TestType).AssemblyQualifiedName), typeof(TestType) },
75
TypeName
name =
TypeName
.Parse(typeof(int).AssemblyQualifiedName);
78
name =
TypeName
.Parse(testName);
88
comparer.Equals(null,
TypeName
.Parse(typeof(int).AssemblyQualifiedName)).Should().BeFalse();
89
comparer.Equals(
TypeName
.Parse(typeof(int).AssemblyQualifiedName), null).Should().BeFalse();
91
TypeName
.Parse(typeof(int).AssemblyQualifiedName),
92
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.FullName}")).Should().BeTrue();
100
int hash = comparer.GetHashCode(
TypeName
.Parse(typeof(int).AssemblyQualifiedName));
101
comparer.GetHashCode(
TypeName
.Parse(typeof(int).AssemblyQualifiedName)).Should().Be(hash);
102
comparer.GetHashCode(
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.FullName}")).Should().Be(hash);
105
public static TheoryData<
TypeName
, Type> TypeNameComparer_FullNameMatch_Success() => new()
107
{
TypeName
.Parse("System.Int32"), typeof(int) },
108
{
TypeName
.Parse("System.Int32[]"), typeof(int[]) },
109
{
TypeName
.Parse("System.Collections.Generic.List`1[[System.Int32]]"), typeof(List<int>) },
110
{
TypeName
.Parse(typeof(TestType).FullName), typeof(TestType) },
117
public void DictionaryLookup_FullNameMatch_Succeeds(
TypeName
name, Type expected)
119
var types = new Dictionary<
TypeName
, Type>(TypeNameComparer.FullNameMatch)
121
{
TypeName
.Parse(typeof(int).FullName), typeof(int) },
122
{
TypeName
.Parse(typeof(int[]).FullName), typeof(int[]) },
123
{
TypeName
.Parse(typeof(List<int>).FullName), typeof(List<int>) },
124
{
TypeName
.Parse(typeof(TestType).FullName), typeof(TestType) },
131
public static TheoryData<
TypeName
> TypeNameComparer_FullNameMatch_Fail() =>
133
TypeName
.Parse("UnknownType"),
134
TypeName
.Parse("List`1[[UnknownType]]"),
135
TypeName
.Parse("Int32"),
136
TypeName
.Parse("Int32[]"),
137
TypeName
.Parse("System.Collections.Generic.List`1[[Int32]]"),
138
TypeName
.Parse(nameof(TestType))
143
public void DictionaryLookup_FullNameMatch_Fails(
TypeName
name)
145
var types = new Dictionary<
TypeName
, Type>(TypeNameComparer.FullNameMatch)
147
{
TypeName
.Parse(typeof(int).FullName), typeof(int) },
148
{
TypeName
.Parse(typeof(int[]).FullName), typeof(int[]) },
149
{
TypeName
.Parse(typeof(List<int>).FullName), typeof(List<int>) },
150
{
TypeName
.Parse(typeof(TestType).FullName), typeof(TestType) },
156
public static TheoryData<
TypeName
, Type> TypeNameComparer_FullNameAndAssemblyNameMatch_Success() => new()
158
{
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int) },
159
{
TypeName
.Parse($"{typeof(int[]).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int[]) },
160
{
TypeName
.Parse($"{typeof(List<int>).FullName}, {typeof(List<int>).Assembly.GetName().Name}"), typeof(List<int>) },
161
{
TypeName
.Parse($"{typeof(TestType).FullName}, {typeof(TestType).Assembly.GetName().Name}"), typeof(TestType) },
167
public void DictionaryLookup_FullNameAndAssemblyNameMatch_Succeeds(
TypeName
name, Type expected)
169
var types = new Dictionary<
TypeName
, Type>(TypeNameComparer.FullNameAndAssemblyNameMatch)
171
{
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int) },
172
{
TypeName
.Parse($"{typeof(int[]).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int[]) },
173
{
TypeName
.Parse($"{typeof(List<int>).FullName}, {typeof(List<int>).Assembly.GetName().Name}"), typeof(List<int>) },
174
{
TypeName
.Parse($"{typeof(TestType).FullName}, {typeof(TestType).Assembly.GetName().Name}"), typeof(TestType) },
181
public static TheoryData<
TypeName
> TypeNameComparer_FullNameAndAssemblyNameMatch_Fail() => new()
184
TypeName
.Parse($"{typeof(int).FullName}, SomeOtherAssembly"),
186
TypeName
.Parse($"SomeNamespace.SomeType, {typeof(int).Assembly.GetName().Name}"),
188
TypeName
.Parse("SomeNamespace.SomeType, SomeOtherAssembly"),
190
TypeName
.Parse($"{typeof(int).FullName}"),
192
TypeName
.Parse($"System.String, {typeof(int).Assembly.GetName().Name}"),
198
public void DictionaryLookup_FullNameAndAssemblyNameMatch_Fails(
TypeName
name)
200
var types = new Dictionary<
TypeName
, Type>(TypeNameComparer.FullNameAndAssemblyNameMatch)
202
{
TypeName
.Parse($"{typeof(int).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int) },
203
{
TypeName
.Parse($"{typeof(int[]).FullName}, {typeof(int).Assembly.GetName().Name}"), typeof(int[]) },
204
{
TypeName
.Parse($"{typeof(List<int>).FullName}, {typeof(List<int>).Assembly.GetName().Name}"), typeof(List<int>) },
205
{
TypeName
.Parse($"{typeof(TestType).FullName}, {typeof(TestType).Assembly.GetName().Name}"), typeof(TestType) },
System\TypeExtensionsTests.cs (45)
12
public static TheoryData<Type,
TypeName
, int, bool> Matches_Type_Data() => new()
14
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.All, true },
15
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AllButAssemblyVersion, true },
16
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.TypeFullName, true },
17
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AssemblyVersion, true },
18
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AssemblyCultureName, true },
19
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AssemblyName, true },
20
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AssemblyPublicKeyToken, true },
21
{ typeof(int),
TypeName
.Parse($"System.Int32, {Assemblies.Mscorlib}"), (int)TypeNameComparison.AllButAssemblyVersion, false },
22
{ typeof(int),
TypeName
.Parse($"System.Int32, {Assemblies.Mscorlib}"), (int)TypeNameComparison.TypeFullName, true },
23
{ typeof(int),
TypeName
.Parse($"Int32, {Assemblies.Mscorlib}"), (int)TypeNameComparison.TypeFullName, false },
24
{ typeof(int?),
TypeName
.Parse(typeof(int).AssemblyQualifiedName), (int)TypeNameComparison.AllButAssemblyVersion, false },
25
{ typeof(int?),
TypeName
.Parse(typeof(int?).AssemblyQualifiedName), (int)TypeNameComparison.All, true },
26
{ typeof(int?[]),
TypeName
.Parse($"System.Nullable`1[[System.Int32, {Assemblies.Mscorlib}]][], {Assemblies.Mscorlib}"), (int)TypeNameComparison.AllButAssemblyVersion, false},
27
{ typeof(DayOfWeek),
TypeName
.Parse($"System.Nullable`1[[System.DayOfWeek, {Assemblies.Mscorlib}]], {Assemblies.Mscorlib}"), (int)TypeNameComparison.AllButAssemblyVersion, false },
29
{ typeof(int),
TypeName
.Parse(typeof(int).AssemblyQualifiedName!.Replace("neutral", "en-US")), (int)TypeNameComparison.AssemblyCultureName, false },
31
{ typeof(int),
TypeName
.Parse("Int32"), (int)TypeNameComparison.TypeFullName, false },
33
{ typeof(int),
TypeName
.Parse("SYSTEM.Int32"), (int)TypeNameComparison.TypeFullName, false },
35
{ typeof(int),
TypeName
.Parse("System.Int32"), (int)TypeNameComparison.AllButAssemblyVersion, false },
37
{ typeof(int),
TypeName
.Parse($"System.Int32, {typeof(int).Assembly.FullName!.ToUpperInvariant()}"), (int)TypeNameComparison.AssemblyName, false },
42
public void Matches_Type(Type type,
TypeName
typeName, int comparison, bool matches)
45
TypeName
.Parse(type.AssemblyQualifiedName).Matches(typeName, (TypeNameComparison)comparison).Should().Be(matches);
54
TypeName
.Parse(typeof(int).AssemblyQualifiedName!.Replace("7cec85d7bea7798e", "7cec00000ea7798e")),
59
public static TheoryData<
TypeName
,
TypeName
, bool> Matches_Type_Mscorlib_Data() => new()
61
{
TypeName
.Parse($"System.Int32, {Assemblies.Mscorlib}"),
TypeName
.Parse($"System.Int32, {Assemblies.Mscorlib}"), true },
62
{
TypeName
.Parse($"System.Int32, {Assemblies.Mscorlib}"),
TypeName
.Parse($"System.String, {Assemblies.Mscorlib}"), false },
63
{
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], {Assemblies.Mscorlib}"),
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], {Assemblies.Mscorlib}"), true },
64
{
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], {Assemblies.Mscorlib}"),
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], {Assemblies.Mscorlib}"), false },
65
{
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], {Assemblies.Mscorlib}"),
TypeName
.Parse($"System.Collections.Generic.Dictionary`2[[System.String, {Assemblies.Mscorlib}],[System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]], mscorlib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"), false },
66
{
TypeName
.Parse($"System.Drawing.Bitmap[], System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
TypeName
.Parse($"System.Drawing.Bitmap[], System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), true },
67
{
TypeName
.Parse($"System.Drawing.Bitmap[], System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
TypeName
.Parse($"System.Drawing.Bitmap[], System.Drawing, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), false },
68
{
TypeName
.Parse($"System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
TypeName
.Parse($"System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), true },
69
{
TypeName
.Parse($"System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
TypeName
.Parse($"System.Drawing.Bitmap, System.Drawing, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), false },
74
public void Matches_Type_Mscorlib(
TypeName
x,
TypeName
y, bool matches) =>
System.Reflection.Metadata (59)
System\Reflection\Metadata\TypeName.cs (47)
35
private readonly
TypeName
? _elementOrGenericType;
36
private readonly
TypeName
? _declaringType;
40
private readonly ImmutableArray<
TypeName
> _genericArguments;
46
TypeName
? elementOrGenericType = default,
47
TypeName
? declaringType = default,
51
ImmutableArray<
TypeName
>.Builder? genericTypeArguments = default,
67
? ImmutableArray<
TypeName
>.Empty
75
TypeName
? elementOrGenericType,
76
TypeName
? declaringType,
77
ImmutableArray<
TypeName
> genericTypeArguments,
133
/// Returns assembly name which contains this type, or null if this <see cref="
TypeName
"/> was not
146
public
TypeName
DeclaringType
210
foreach (
TypeName
genericArg in GetGenericArguments())
376
TypeName
rootTypeName = this;
414
/// Represents the total number of <see cref="
TypeName
"/> instances that are used to describe
420
/// as the total number of <see cref="
TypeName
"/> instances that would be created if
421
/// you were to totally deconstruct this instance and visit each intermediate <see cref="
TypeName
"/>
428
/// involves inspecting 8 <see cref="
TypeName
"/> instances total:
441
/// <exception cref="OverflowException">The total number of <see cref="
TypeName
"/> instances that are used to describe
459
foreach (
TypeName
genericArgument in GetGenericArguments())
479
public
TypeName
GetElementType()
496
public
TypeName
GetGenericTypeDefinition()
514
public static
TypeName
Parse(ReadOnlySpan<char> typeName, TypeNameParseOptions? options = default)
524
public static bool TryParse(ReadOnlySpan<char> typeName, [NotNullWhen(true)] out
TypeName
? result, TypeNameParseOptions? options = default)
565
/// If this <see cref="
TypeName
"/> represents a constructed generic type, returns an array
576
ImmutableArray<
TypeName
> GetGenericArguments() => _genericArguments;
581
/// Creates a new <see cref="
TypeName
" /> object that represents current simple name with provided assembly name.
586
public
TypeName
WithAssemblyName(AssemblyNameInfo? assemblyName)
604
TypeName
? declaringType = IsNested
612
genericTypeArguments: ImmutableArray<
TypeName
>.Empty,
617
/// Creates a <see cref="
TypeName
" /> object representing a one-dimensional array
621
/// A <see cref="
TypeName
" /> object representing a one-dimensional array
624
public
TypeName
MakeSZArrayTypeName() => MakeElementTypeName(TypeNameParserHelpers.SZArray);
627
/// Creates a <see cref="
TypeName
" /> object representing an array of the current type,
632
/// A <see cref="
TypeName
" /> object representing an array of the current type,
636
public
TypeName
MakeArrayTypeName(int rank)
642
/// Creates a <see cref="
TypeName
" /> object that represents a pointer to the current type.
645
/// A <see cref="
TypeName
" /> object that represents a pointer to the current type.
647
public
TypeName
MakePointerTypeName() => MakeElementTypeName(TypeNameParserHelpers.Pointer);
650
/// Creates a <see cref="
TypeName
" /> object that represents a managed reference to the current type.
653
/// A <see cref="
TypeName
" /> object that represents a managed reference to the current type.
655
public
TypeName
MakeByRefTypeName() => MakeElementTypeName(TypeNameParserHelpers.ByRef);
662
/// A <see cref="
TypeName
" /> representing the constructed type name formed by using the elements
666
public
TypeName
MakeGenericTypeName(ImmutableArray<
TypeName
> typeArguments)
676
private
TypeName
MakeElementTypeName(int rankOrModifier)
682
genericTypeArguments: ImmutableArray<
TypeName
>.Empty,
System\Reflection\Metadata\TypeNameParser.cs (10)
31
internal static
TypeName
? Parse(ReadOnlySpan<char> typeName, bool throwOnError, TypeNameParseOptions? options = default)
46
TypeName
? parsedName = parser.ParseNextTypeName(allowFullyQualifiedName: true, ref recursiveDepth);
70
private
TypeName
? ParseNextTypeName(bool allowFullyQualifiedName, ref int recursiveDepth)
92
ImmutableArray<
TypeName
>.Builder? genericArgs = null;
108
TypeName
? genericArg = ParseNextTypeName(allowFullyQualifiedName: doubleBrackets, ref recursiveDepth);
125
genericArgs = ImmutableArray.CreateBuilder<
TypeName
>(2);
206
TypeName
? declaringType = GetDeclaringType(fullName, nestedNameLengths, assemblyName);
207
TypeName
result = new(fullName, assemblyName, declaringType: declaringType);
252
private static
TypeName
? GetDeclaringType(string fullTypeName, List<int>? nestedNameLengths, AssemblyNameInfo? assemblyName)
261
TypeName
? declaringType = null;
System\Reflection\Metadata\TypeNameParserOptions.cs (2)
11
/// Limits the maximum value of <seealso cref="
TypeName
.GetNodeCount">node count</seealso> that parser can handle.
15
/// Setting this to a large value can render <see cref="
TypeName
"/> susceptible to Denial of Service
System.Resources.Extensions (3)
System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.ITypeResolver.cs (1)
21
Type GetType(
TypeName
typeName);
System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.TypeResolver.cs (2)
38
Type ITypeResolver.GetType(
TypeName
typeName)
88
private static Type? GetSimplyNamedTypeFromAssembly(Assembly assembly,
TypeName
typeName)
System.Windows.Forms (25)
System\Resources\ResXSerializationBinder.cs (4)
40
if (_typeResolver is null || !
TypeName
.TryParse($"{typeName}, {assemblyName}".AsSpan(), out
TypeName
? parsed))
83
&&
TypeName
.TryParse(assemblyQualifiedTypeName.AsSpan(), out
TypeName
? parsed)
System\Windows\Forms\Nrbf\WinFormsNrbfSerializer.cs (2)
17
private static Dictionary<
TypeName
, Type>? s_knownTypes;
22
public static bool TryBindToType(
TypeName
typeName, [NotNullWhen(true)] out Type? type)
System\Windows\Forms\OLE\Clipboard.cs (9)
165
/// <see cref="
TypeName
"/> is allowed or throws a <see cref="NotSupportedException"/> if <see cref="
TypeName
"/> is not
189
/// <see cref="
TypeName
"/> parameter can be matched according to the user requirements, for example, only namespace-qualified
229
/// Avoid loading assemblies named in the <see cref="
TypeName
"/> argument of your <paramref name="resolver"/>.
235
/// should be aware of <see cref="
TypeName
"/>s coming in with either .NET Framework assembly names or .NET ones.
243
/// <see cref="
TypeName
.FullName"/> property.
307
Func<
TypeName
, Type?> resolver,
325
/// You must use the <see cref="TryGetData{T}(string, Func{
TypeName
, Type?}, out T)"/> with an explicit resolver.
339
/// <inheritdoc cref="TryGetData{T}(string, Func{
TypeName
, Type}, out T)"/>
System\Windows\Forms\OLE\DataObject.cs (5)
150
/// <inheritdoc cref="Clipboard.TryGetData{T}(string, Func{
TypeName
, Type}, out T)"/>
154
Func<
TypeName
, Type?> resolver,
183
/// <inheritdoc cref="ITypedDataObject.TryGetData{T}(string, Func{
TypeName
, Type}, bool, out T)" />
187
Func<
TypeName
, Type?>? resolver,
264
Func<
TypeName
, Type?>? resolver,
System\Windows\Forms\OLE\DataObjectAdapter.cs (1)
41
Func<
TypeName
, Type?> resolver,
System\Windows\Forms\OLE\DataObjectExtensions.cs (2)
52
/// <inheritdoc cref="ITypedDataObject.TryGetData{T}(string, Func{Reflection.Metadata.
TypeName
, Type}, bool, out T)"/>
59
Func<Reflection.Metadata.
TypeName
, Type?> resolver,
System\Windows\Forms\OLE\ITypedDataObject.cs (2)
39
/// <inheritdoc cref="IDataObjectInternal.TryGetData{T}(string, Func{
TypeName
, Type}, bool, out T)" />
43
Func<
TypeName
, Type?> resolver,
System.Windows.Forms.Tests (26)
System\Resources\ResXSerializationBinderTests.cs (2)
86
TypeName
parsed =
TypeName
.Parse($"{typeof(Form).FullName}, {typeof(Form).Assembly.FullName}");
System\Windows\Forms\BinaryFormat\WinFormsBinaryFormattedObjectTests.cs (2)
95
if (
TypeName
.TryParse(InnerTypeAssemblyQualifiedName, out
TypeName
? innerTypeName)
System\Windows\Forms\ClipboardTests.cs (9)
778
public static Type TestDataResolver(
TypeName
typeName)
1056
TypeName
.TryParse(innerTypeAssemblyQualifiedName, out
TypeName
? innerTypeName).Should().BeTrue();
1057
TypeName
checkedResult = innerTypeName.Should().BeOfType<
TypeName
>().Subject;
1337
(
TypeName
name) => name.FullName == typeof(SerializableTestData).FullName ? typeof(SerializableTestData) : null,
1345
(
TypeName
name) => name.FullName == typeof(SerializableTestData).FullName ? typeof(SerializableTestData) : null,
1387
(
TypeName
name) => name.FullName == typeof(SerializableTestData).FullName ? typeof(SerializableTestData) : null,
1405
(
TypeName
name) => name.FullName == typeof(SerializableTestData).FullName ? typeof(SerializableTestData) : null,
System\Windows\Forms\DataObjectExtensionsTests.cs (2)
30
private static Type Resolver(
TypeName
typeName) => typeof(string);
252
public bool TryGetData<T>(string format, Func<
TypeName
, Type?> resolver, bool autoConvert, [MaybeNullWhen(false), NotNullWhen(true)] out T data)
System\Windows\Forms\DataObjectTests.cs (5)
377
private readonly Func<
TypeName
, Type>? _resolver;
381
public DataObjectOverridesTryGetDataCore(string format, Func<
TypeName
, Type>? resolver, bool autoConvert) : base()
389
public static Type Resolver(
TypeName
_) => typeof(string);
393
Func<
TypeName
, Type?>? resolver,
523
private static Type NotSupportedResolver(
TypeName
typeName) => throw new NotSupportedException();
System\Windows\Forms\NativeToWinFormsAdapterTests.cs (4)
44
(
TypeName
typeName) => typeof(int).Matches(typeName, TypeNameComparison.TypeFullName) ? typeof(int) : null,
66
static Type Resolver(
TypeName
typeName) => typeof(int);
489
public static Type Resolver(
TypeName
typeName)
547
public static Type? Resolver(
TypeName
typeName)
System\Windows\Forms\Ole\BinaryFormatUtilitiesTests.cs (2)
19
Func<
TypeName
, Type>? resolver,
69
private static Type FontResolver(
TypeName
typeName)
System.Windows.Forms.TestUtilities (2)
Data\TypedAndRuntimeDataObject.cs (1)
32
Func<
TypeName
, Type?> resolver,
Data\TypedDataObject.cs (1)
31
Func<
TypeName
, Type?> resolver,