Skip to content

Resolve type kind #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: metadata-provider
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion MetadataProvider/SignatureTypeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using SRM = System.Reflection.Metadata;

Expand Down Expand Up @@ -50,6 +51,7 @@ public virtual IType GetPrimitiveType(SRM.PrimitiveTypeCode typeCode)
public virtual IType GetTypeFromDefinition(SRM.MetadataReader reader, SRM.TypeDefinitionHandle handle, byte rawTypeKind = 0)
{
var result = extractor.GetDefinedType(handle);
result.TypeKind = ResolveTypeKind(reader, handle, rawTypeKind);
return result;
}

Expand All @@ -63,7 +65,8 @@ public virtual IType GetTypeFromReference(SRM.MetadataReader reader, SRM.TypeRef
var type = new BasicType(name)
{
ContainingNamespace = namespaze,
GenericParameterCount = genericParameterCount
GenericParameterCount = genericParameterCount,
TypeKind = ResolveTypeKind(reader, handle, rawTypeKind)
};

type.Resolve(extractor.Host);
Expand Down Expand Up @@ -232,5 +235,20 @@ public virtual IType GetFunctionPointerType(SRM.MethodSignature<IType> signature

return result;
}

private TypeKind ResolveTypeKind(SRM.MetadataReader reader, SRM.EntityHandle typeHandle, byte rawTypeKind)
{
var typeKind = reader.ResolveSignatureTypeKind(typeHandle, rawTypeKind);
switch (typeKind)
{
case SRM.SignatureTypeKind.Class:
return TypeKind.ReferenceType;
case SRM.SignatureTypeKind.ValueType:
return TypeKind.ValueType;
default:
return TypeKind.Unknown;
}

}
}
}