Example #1
0
 public static EcmaMethodIL Create(EcmaMethod method)
 {
     var rva = method.MetadataReader.GetMethodDefinition(method.Handle).RelativeVirtualAddress;
     if (rva == 0)
         return null;
     return new EcmaMethodIL(method, rva);
 }
Example #2
0
        public static CustomAttributeValue <TypeDesc>?GetDecodedCustomAttribute(this EcmaMethod This,
                                                                                string attributeNamespace, string attributeName)
        {
            var metadataReader = This.MetadataReader;

            var attributeHandle = metadataReader.GetCustomAttributeHandle(metadataReader.GetMethodDefinition(This.Handle).GetCustomAttributes(),
                                                                          attributeNamespace, attributeName);

            if (attributeHandle.IsNil)
            {
                return(null);
            }

            return(metadataReader.GetCustomAttribute(attributeHandle).DecodeValue(new CustomAttributeTypeProvider(This.Module)));
        }
Example #3
0
        public static IEnumerable <CustomAttributeValue <TypeDesc> > GetDecodedCustomAttributes(this EcmaMethod This,
                                                                                                string attributeNamespace, string attributeName)
        {
            var metadataReader   = This.MetadataReader;
            var attributeHandles = metadataReader.GetMethodDefinition(This.Handle).GetCustomAttributes();

            foreach (var attributeHandle in attributeHandles)
            {
                if (IsEqualCustomAttributeName(attributeHandle, metadataReader, attributeNamespace, attributeName))
                {
                    yield return(metadataReader.GetCustomAttribute(attributeHandle).DecodeValue(new CustomAttributeTypeProvider(This.Module)));
                }
            }
        }
Example #4
0
 private EcmaMethodIL(EcmaMethod method, int rva)
 {
     _method = method;
     _module = method.Module;
     _methodBody = _module.PEReader.GetMethodBody(rva);
 }
Example #5
0
        public static IEnumerable <CustomAttributeValue <TypeDesc> > GetDecodedCustomAttributes(this EcmaMethod This,
                                                                                                string attributeNamespace, string attributeName)
        {
            var metadataReader   = This.MetadataReader;
            var attributeHandles = metadataReader.GetMethodDefinition(This.Handle).GetCustomAttributes();

            foreach (var attributeHandle in attributeHandles)
            {
                StringHandle namespaceHandle, nameHandle;
                if (!metadataReader.GetAttributeNamespaceAndName(attributeHandle, out namespaceHandle, out nameHandle))
                {
                    continue;
                }

                if (metadataReader.StringComparer.Equals(namespaceHandle, attributeNamespace) &&
                    metadataReader.StringComparer.Equals(nameHandle, attributeName))
                {
                    yield return(metadataReader.GetCustomAttribute(attributeHandle).DecodeValue(new CustomAttributeTypeProvider(This.Module)));
                }
            }
        }
Example #6
0
            protected override IEntityHandleObject CreateValueFromKey(EntityHandle handle)
            {
                object item;

                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                    item = new EcmaType(_module, (TypeDefinitionHandle)handle);
                    break;

                case HandleKind.MethodDefinition:
                {
                    MethodDefinitionHandle methodDefinitionHandle = (MethodDefinitionHandle)handle;
                    TypeDefinitionHandle   typeDefinitionHandle   = _module._metadataReader.GetMethodDefinition(methodDefinitionHandle).GetDeclaringType();
                    EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle);
                    item = new EcmaMethod(type, methodDefinitionHandle);
                }
                break;

                case HandleKind.FieldDefinition:
                {
                    FieldDefinitionHandle fieldDefinitionHandle = (FieldDefinitionHandle)handle;
                    TypeDefinitionHandle  typeDefinitionHandle  = _module._metadataReader.GetFieldDefinition(fieldDefinitionHandle).GetDeclaringType();
                    EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle);
                    item = new EcmaField(type, fieldDefinitionHandle);
                }
                break;

                case HandleKind.TypeReference:
                    item = _module.ResolveTypeReference((TypeReferenceHandle)handle);
                    break;

                case HandleKind.MemberReference:
                    item = _module.ResolveMemberReference((MemberReferenceHandle)handle);
                    break;

                case HandleKind.AssemblyReference:
                    item = _module.ResolveAssemblyReference((AssemblyReferenceHandle)handle);
                    break;

                case HandleKind.TypeSpecification:
                    item = _module.ResolveTypeSpecification((TypeSpecificationHandle)handle);
                    break;

                case HandleKind.MethodSpecification:
                    item = _module.ResolveMethodSpecification((MethodSpecificationHandle)handle);
                    break;

                case HandleKind.ExportedType:
                    item = _module.ResolveExportedType((ExportedTypeHandle)handle);
                    break;

                case HandleKind.StandaloneSignature:
                    item = _module.ResolveStandaloneSignature((StandaloneSignatureHandle)handle);
                    break;

                case HandleKind.ModuleDefinition:
                    // ECMA-335 Partition 2 II.22.38 1d: This should not occur in a CLI ("compressed metadata") module,
                    // but resolves to "current module".
                    item = _module;
                    break;

                default:
                    throw new BadImageFormatException("Unknown metadata token type: " + handle.Kind);
                }

                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                case HandleKind.MethodDefinition:
                case HandleKind.FieldDefinition:
                    // type/method/field definitions directly correspond to their target item.
                    return((IEntityHandleObject)item);

                default:
                    // Everything else is some form of reference which cannot be self-describing
                    return(new EcmaObjectLookupWrapper(handle, item));
                }
            }
Example #7
0
 public static bool IsSpecialName(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.SpecialName) != 0);
 }
Example #8
0
            protected override IEntityHandleObject CreateValueFromKey(EntityHandle handle)
            {
                object item;

                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                    item = new EcmaType(_module, (TypeDefinitionHandle)handle);
                    break;

                case HandleKind.MethodDefinition:
                {
                    MethodDefinitionHandle methodDefinitionHandle = (MethodDefinitionHandle)handle;
                    TypeDefinitionHandle   typeDefinitionHandle   = _module._metadataReader.GetMethodDefinition(methodDefinitionHandle).GetDeclaringType();
                    EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle);
                    item = new EcmaMethod(type, methodDefinitionHandle);
                }
                break;

                case HandleKind.FieldDefinition:
                {
                    FieldDefinitionHandle fieldDefinitionHandle = (FieldDefinitionHandle)handle;
                    TypeDefinitionHandle  typeDefinitionHandle  = _module._metadataReader.GetFieldDefinition(fieldDefinitionHandle).GetDeclaringType();
                    EcmaType type = (EcmaType)_module.GetObject(typeDefinitionHandle);
                    item = new EcmaField(type, fieldDefinitionHandle);
                }
                break;

                case HandleKind.TypeReference:
                    item = _module.ResolveTypeReference((TypeReferenceHandle)handle);
                    break;

                case HandleKind.MemberReference:
                    item = _module.ResolveMemberReference((MemberReferenceHandle)handle);
                    break;

                case HandleKind.AssemblyReference:
                    item = _module.ResolveAssemblyReference((AssemblyReferenceHandle)handle);
                    break;

                case HandleKind.TypeSpecification:
                    item = _module.ResolveTypeSpecification((TypeSpecificationHandle)handle);
                    break;

                case HandleKind.MethodSpecification:
                    item = _module.ResolveMethodSpecification((MethodSpecificationHandle)handle);
                    break;

                case HandleKind.ExportedType:
                    item = _module.ResolveExportedType((ExportedTypeHandle)handle);
                    break;

                // TODO: Resolve other tokens

                default:
                    throw new BadImageFormatException("Unknown metadata token type");
                }

                switch (handle.Kind)
                {
                case HandleKind.TypeDefinition:
                case HandleKind.MethodDefinition:
                case HandleKind.FieldDefinition:
                    // type/method/field definitions directly correspond to their target item.
                    return((IEntityHandleObject)item);

                default:
                    // Everything else is some form of reference which cannot be self-describing
                    return(new EcmaObjectLookupWrapper(handle, item));
                }
            }
Example #9
0
 public static bool IsAbstract(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.Abstract) != 0);
 }
Example #10
0
 public static bool IsHideBySig(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.HideBySig) != 0);
 }
Example #11
0
 public static bool IsFinal(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.Final) != 0);
 }
Example #12
0
 public static bool IsStatic(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.Static) != 0);
 }
Example #13
0
 public static bool IsPrivate(this EcmaMethod method)
 {
     return((method.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private);
 }