本文整理汇总了C#中System.Reflection.Metadata.MetadataReader.GetMethodDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader.GetMethodDefinition方法的具体用法?C# MetadataReader.GetMethodDefinition怎么用?C# MetadataReader.GetMethodDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.MetadataReader
的用法示例。
在下文中一共展示了MetadataReader.GetMethodDefinition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetAttributeName
/// <summary>Gets the name of an attribute.</summary>
/// <param name="reader">The metadata reader.</param>
/// <param name="attr">The attribute.</param>
/// <param name="typeNamespaceHandle">The namespace of the attribute.</param>
/// <param name="typeNameHandle">The name of the attribute.</param>
/// <returns>true if the name could be retrieved; otherwise, false.</returns>
private static bool TryGetAttributeName(MetadataReader reader, CustomAttribute attr, out StringHandle typeNamespaceHandle, out StringHandle typeNameHandle)
{
EntityHandle ctorHandle = attr.Constructor;
switch (ctorHandle.Kind)
{
case HandleKind.MemberReference:
EntityHandle container = reader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
if (container.Kind == HandleKind.TypeReference)
{
TypeReference tr = reader.GetTypeReference((TypeReferenceHandle)container);
typeNamespaceHandle = tr.Namespace;
typeNameHandle = tr.Name;
return true;
}
break;
case HandleKind.MethodDefinition:
MethodDefinition md = reader.GetMethodDefinition((MethodDefinitionHandle)ctorHandle);
TypeDefinition td = reader.GetTypeDefinition(md.GetDeclaringType());
typeNamespaceHandle = td.Namespace;
typeNameHandle = td.Name;
return true;
}
// Unusual case, potentially invalid IL
typeNamespaceHandle = default(StringHandle);
typeNameHandle = default(StringHandle);
return false;
}
示例2: GetStringAttributeArgumentValue
/// <summary>Gets the string argument value of an attribute with a single fixed string argument.</summary>
/// <param name="reader">The metadata reader.</param>
/// <param name="attr">The attribute.</param>
/// <param name="value">The value parsed from the attribute, if it could be retrieved; otherwise, the value is left unmodified.</param>
private static void GetStringAttributeArgumentValue(MetadataReader reader, CustomAttribute attr, ref string value)
{
EntityHandle ctorHandle = attr.Constructor;
BlobHandle signature;
switch (ctorHandle.Kind)
{
case HandleKind.MemberReference:
signature = reader.GetMemberReference((MemberReferenceHandle)ctorHandle).Signature;
break;
case HandleKind.MethodDefinition:
signature = reader.GetMethodDefinition((MethodDefinitionHandle)ctorHandle).Signature;
break;
default:
// Unusual case, potentially invalid IL
return;
}
BlobReader signatureReader = reader.GetBlobReader(signature);
BlobReader valueReader = reader.GetBlobReader(attr.Value);
const ushort Prolog = 1; // two-byte "prolog" defined by ECMA-335 (II.23.3) to be at the beginning of attribute value blobs
if (valueReader.ReadUInt16() == Prolog)
{
SignatureHeader header = signatureReader.ReadSignatureHeader();
int parameterCount;
if (header.Kind == SignatureKind.Method && // attr ctor must be a method
!header.IsGeneric && // attr ctor must be non-generic
signatureReader.TryReadCompressedInteger(out parameterCount) && // read parameter count
parameterCount == 1 && // attr ctor must have 1 parameter
signatureReader.ReadSignatureTypeCode() == SignatureTypeCode.Void && // attr ctor return type must be void
signatureReader.ReadSignatureTypeCode() == SignatureTypeCode.String) // attr ctor first parameter must be string
{
value = valueReader.ReadSerializedString();
}
}
}
示例3: LookupMetadataDefinitions
private static void LookupMetadataDefinitions(
MetadataReader reader, TypeDefinition typeDefinition,
OrderPreservingMultiDictionary<string, MetadataDefinition> definitionMap)
{
// Only bother looking for extension methods in static types.
if ((typeDefinition.Attributes & TypeAttributes.Abstract) != 0 &&
(typeDefinition.Attributes & TypeAttributes.Sealed) != 0)
{
foreach (var child in typeDefinition.GetMethods())
{
var method = reader.GetMethodDefinition(child);
if ((method.Attributes & MethodAttributes.SpecialName) != 0 ||
(method.Attributes & MethodAttributes.RTSpecialName) != 0)
{
continue;
}
// SymbolTreeInfo is only searched for types and extension methods.
// So we don't want to pull in all methods here. As a simple approximation
// we just pull in methods that have attributes on them.
if ((method.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public &&
(method.Attributes & MethodAttributes.Static) != 0 &&
method.GetCustomAttributes().Count > 0)
{
var definition = new MetadataDefinition(
MetadataDefinitionKind.Member, reader.GetString(method.Name));
definitionMap.Add(definition.Name, definition);
}
}
}
foreach (var child in typeDefinition.GetNestedTypes())
{
var type = reader.GetTypeDefinition(child);
// We don't include internals from metadata assemblies. It's less likely that
// a project would have IVT to it and so it helps us save on memory. It also
// means we can avoid loading lots and lots of obfuscated code in the case the
// dll was obfuscated.
if (IsPublic(type.Attributes))
{
var definition = MetadataDefinition.Create(reader, type);
definitionMap.Add(definition.Name, definition);
}
}
}
示例4: GetMethodCount
private static int GetMethodCount(MetadataReader reader, TypeDefinition type)
{
var count = 0;
foreach (var handle in type.GetMethods())
{
var methodDefinition = reader.GetMethodDefinition(handle);
if (methodDefinition.GetCustomAttributes().Count == 0 ||
!IsValidIdentifier(reader, methodDefinition.Name))
{
continue;
}
if (MethodAttributes.Public != (methodDefinition.Attributes & MethodAttributes.Public))
{
continue;
}
count++;
}
return count;
}
示例5: GetQualifiedMethodName
private static string GetQualifiedMethodName(MetadataReader metadataReader, MethodDefinitionHandle methodHandle)
{
var method = metadataReader.GetMethodDefinition(methodHandle);
var containingTypeHandle = method.GetDeclaringType();
string fullTypeName = GetFullTypeName(metadataReader, containingTypeHandle);
string methodName = metadataReader.GetString(method.Name);
return fullTypeName != null ? fullTypeName + "." + methodName : methodName;
}
示例6: GetTokenForMethod
private static MethodDefinitionHandle GetTokenForMethod(MetadataReader metadataReader, string methodName)
{
Assert.NotNull(methodName);
Assert.NotEmpty(methodName);
foreach (var methodDef in metadataReader.MethodDefinitions)
{
string name = metadataReader.GetString(metadataReader.GetMethodDefinition(methodDef).Name);
if (methodName.Equals(name))
{
return methodDef;
}
}
AssertEx.Fail("Unable to find method:" + methodName);
return default(MethodDefinitionHandle);
}
示例7: GetAttributeParentNameAndKind
private static void GetAttributeParentNameAndKind(MetadataReader metadataReader, Handle token, out string name, out SymbolKind kind)
{
switch (token.Kind)
{
case HandleKind.AssemblyDefinition:
name = null;
kind = SymbolKind.Assembly;
return;
case HandleKind.TypeDefinition:
name = metadataReader.GetString(metadataReader.GetTypeDefinition((TypeDefinitionHandle)token).Name);
kind = SymbolKind.NamedType;
return;
case HandleKind.MethodDefinition:
name = metadataReader.GetString(metadataReader.GetMethodDefinition((MethodDefinitionHandle)token).Name);
kind = SymbolKind.Method;
return;
default:
throw TestExceptionUtilities.UnexpectedValue(token.Kind);
}
}
示例8: IsPubliclyVisible
private bool IsPubliclyVisible(MetadataReader referenceMetadata, PropertyDefinition propertyDefinition, bool checkDeclaringType = false)
{
PropertyAccessors propertyAccessors = propertyDefinition.GetAccessors();
if (!propertyAccessors.Getter.IsNil)
{
MethodDefinition getterMethodDefinition = referenceMetadata.GetMethodDefinition(propertyAccessors.Getter);
if (IsPubliclyVisible(referenceMetadata, getterMethodDefinition, checkDeclaringType))
return true;
}
if (!propertyAccessors.Setter.IsNil)
{
MethodDefinition setterMethodDefinition = referenceMetadata.GetMethodDefinition(propertyAccessors.Setter);
if (IsPubliclyVisible(referenceMetadata, setterMethodDefinition, checkDeclaringType))
return true;
}
return false;
}