Using Type from MetaDataLoadContext.LoadFromAssemblyPath(path).GetTypes()
I notice the your IType API is very similar to the Type API but not identical.
And I don't know whether the difference is on purpose but it troubles me they're not quite interchangeable.
For reference, here's my record into which I load the property values:
public record TypeId(
string? AssemblyName,
string? Namespace,
string Name,
Values<TypeId>? GenericTypeArguments,
TypeId? DeclaringType
);
Here's my initializing that from a System.Reflection.Type instance
Here's my initializing that from your IType instance
static TypeId Transform(this IType type)
{
var elementType = (type as TypeWithElementType)?.ElementType ?? type;
var nameSuffix = (type as TypeWithElementType)?.NameSuffix ?? string.Empty;
var assemblyName = elementType.GetDefinition()?.ParentModule?.AssemblyName;
// want a name like "KeyValuePair`2[]" (i.e. with generic arity appended) and not just "KeyValuePair[]"
var name = elementType.GetDefinition()?.MetadataName ?? type.Name;
// we have the name of the element not the type, so add the suffix
name += nameSuffix;
return new TypeId(
assemblyName,
type.Namespace == string.Empty ? null : type.Namespace,
name,
type.TypeArguments.Select(Transform).ToArrayOrNull(),
type.DeclaringType?.Transform()
);
}
In summary the differences I've found so far (after only one day of test-and-debugging) are as follows.
The AssemblyName when the type is an array -- you correctly (i.e. same as Type) display the name e.g. Foo[], and the namespace (of Foo), but not the name of the assembly from which Foo is loaded -- so instead I must fetch that from your ElementType property.
The Namespace, when there isn't one -- you return an empty string, Type returns null.
Whether the name of the type is e.g. KeyValuePair or KeyValuePair2`
I'm viewing type information in two ways:
IType
from theICSharpCode.Decompiler
APIsType
fromMetaDataLoadContext.LoadFromAssemblyPath(path).GetTypes()
I notice the your
IType
API is very similar to theType
API but not identical. And I don't know whether the difference is on purpose but it troubles me they're not quite interchangeable.For reference, here's my record into which I load the property values:
Here's my initializing that from a System.Reflection.Type instance
Here's my initializing that from your IType instance
In summary the differences I've found so far (after only one day of test-and-debugging) are as follows.
Type
) display the name e.g.Foo[]
, and the namespace (ofFoo
), but not the name of the assembly from which Foo is loaded -- so instead I must fetch that from your ElementType property.Type
returns null.KeyValuePair
orKeyValuePair
2`