本文整理汇总了C#中System.Reflection.Metadata.BlobReader.ReadTypeHandle方法的典型用法代码示例。如果您正苦于以下问题:C# BlobReader.ReadTypeHandle方法的具体用法?C# BlobReader.ReadTypeHandle怎么用?C# BlobReader.ReadTypeHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobReader
的用法示例。
在下文中一共展示了BlobReader.ReadTypeHandle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodeType
// cf. MetadataDecoder<>.DecodeTypeOrThrow.
private TypeSignature DecodeType(ref BlobReader signatureReader, SignatureTypeCode typeCode)
{
switch (typeCode)
{
case SignatureTypeCode.TypeHandle:
{
int typeArgumentOffset = 0;
return DecodeType(signatureReader.ReadTypeHandle(), ImmutableArray<TypeSignature>.Empty, ref typeArgumentOffset);
}
case SignatureTypeCode.Array:
{
var elementType = DecodeModifiersAndType(ref signatureReader);
int rank;
int sizes;
signatureReader.TryReadCompressedInteger(out rank);
signatureReader.TryReadCompressedInteger(out sizes);
if (sizes != 0)
{
throw UnhandledMetadata();
}
return new ArrayTypeSignature(elementType, rank);
}
case SignatureTypeCode.SZArray:
{
var elementType = DecodeModifiersAndType(ref signatureReader);
return new ArrayTypeSignature(elementType, 1);
}
case SignatureTypeCode.GenericTypeInstance:
return DecodeGenericTypeInstance(ref signatureReader);
case SignatureTypeCode.Pointer:
{
var pointedAtType = DecodeModifiersAndType(ref signatureReader);
return new PointerTypeSignature(pointedAtType);
}
case SignatureTypeCode.GenericTypeParameter:
return DecodeGenericTypeParameter(ref signatureReader, _allTypeParameters, _containingArity);
case SignatureTypeCode.GenericMethodParameter:
return DecodeGenericTypeParameter(ref signatureReader, _methodTypeParameters, 0);
default:
{
var signature = typeCode.ToSpecialType().GetTypeSignature();
if (signature == null)
{
throw UnhandledMetadata();
}
return signature;
}
}
}
示例2: DecodeGenericTypeInstance
// cf. MetadataDecoder<>.DecodeGenericTypeInstanceOrThrow.
private TypeSignature DecodeGenericTypeInstance(ref BlobReader signatureReader)
{
var typeCode = signatureReader.ReadSignatureTypeCode();
var typeHandle = signatureReader.ReadTypeHandle();
var typeArguments = DecodeGenericTypeArguments(ref signatureReader);
int typeArgumentOffset = 0;
var type = DecodeType(typeHandle, typeArguments, ref typeArgumentOffset);
if (typeArgumentOffset != typeArguments.Length)
{
// Generic type reference names must include arity
// to avoid loading referenced assemblies.
throw UnhandledMetadata();
}
return type;
}
示例3: ImplementsRedirectedInterface
/// <summary>
/// We want to know if a given method implements a redirected interface.
/// For example, if we are given the method RemoveAt on a class "A"
/// which implements the IVector interface (which is redirected
/// to IList in .NET) then this method would return true. The most
/// likely reason why we would want to know this is that we wish to hide
/// (mark private) all methods which implement methods on a redirected
/// interface.
/// </summary>
/// <param name="memberRef">The declaration token for the method</param>
/// <param name="isIDisposable">
/// Returns true if the redirected interface is <see cref="IDisposable"/>.
/// </param>
/// <returns>True if the method implements a method on a redirected interface.
/// False otherwise.</returns>
private bool ImplementsRedirectedInterface(MemberReferenceHandle memberRef, out bool isIDisposable)
{
isIDisposable = false;
EntityHandle parent = MemberRefTable.GetClass(memberRef);
TypeReferenceHandle typeRef;
if (parent.Kind == HandleKind.TypeReference)
{
typeRef = (TypeReferenceHandle)parent;
}
else if (parent.Kind == HandleKind.TypeSpecification)
{
BlobHandle blob = TypeSpecTable.GetSignature((TypeSpecificationHandle)parent);
BlobReader sig = new BlobReader(BlobHeap.GetMemoryBlock(blob));
if (sig.Length < 2 ||
sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_GENERICINST ||
sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_CLASS)
{
return false;
}
EntityHandle token = sig.ReadTypeHandle();
if (token.Kind != HandleKind.TypeReference)
{
return false;
}
typeRef = (TypeReferenceHandle)token;
}
else
{
return false;
}
return GetProjectionIndexForTypeReference(typeRef, out isIDisposable) >= 0;
}