コード例 #1
0
        /// <summary>
        /// This should produce a string representation of the entity for search to match search strings against.
        /// </summary>
        public virtual string GetEntityName(PEFile module, EntityHandle handle, bool fullName)
        {
            MetadataReader metadata = module.Metadata;

            switch (handle.Kind)
            {
            case HandleKind.TypeDefinition:
                if (fullName)
                {
                    return(((TypeDefinitionHandle)handle).GetFullTypeName(metadata).ToILNameString());
                }
                var td = metadata.GetTypeDefinition((TypeDefinitionHandle)handle);
                return(metadata.GetString(td.Name));

            case HandleKind.FieldDefinition:
                var fd            = metadata.GetFieldDefinition((FieldDefinitionHandle)handle);
                var declaringType = fd.GetDeclaringType();
                if (fullName)
                {
                    return(fd.GetDeclaringType().GetFullTypeName(metadata).ToILNameString() + "." + metadata.GetString(fd.Name));
                }
                return(metadata.GetString(fd.Name));

            case HandleKind.MethodDefinition:
                var md = metadata.GetMethodDefinition((MethodDefinitionHandle)handle);
                declaringType = md.GetDeclaringType();
                string methodName        = metadata.GetString(md.Name);
                int    genericParamCount = md.GetGenericParameters().Count;
                if (genericParamCount > 0)
                {
                    methodName += "``" + genericParamCount;
                }
                if (fullName)
                {
                    return(md.GetDeclaringType().GetFullTypeName(metadata).ToILNameString() + "." + methodName);
                }
                return(methodName);

            case HandleKind.EventDefinition:
                var ed = metadata.GetEventDefinition((EventDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(ed.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(declaringType.GetFullTypeName(metadata).ToILNameString() + "." + metadata.GetString(ed.Name));
                }
                return(metadata.GetString(ed.Name));

            case HandleKind.PropertyDefinition:
                var pd = metadata.GetPropertyDefinition((PropertyDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(pd.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(declaringType.GetFullTypeName(metadata).ToILNameString() + "." + metadata.GetString(pd.Name));
                }
                return(metadata.GetString(pd.Name));

            default:
                return(null);
            }
        }
コード例 #2
0
ファイル: SRMExtensions.cs プロジェクト: zwkjgs/ILSpy
        public static TypeDefinitionHandle GetDeclaringType(this EntityHandle entity, MetadataReader metadata)
        {
            switch (entity.Kind)
            {
            case HandleKind.TypeDefinition:
                var td = metadata.GetTypeDefinition((TypeDefinitionHandle)entity);
                return(td.GetDeclaringType());

            case HandleKind.FieldDefinition:
                var fd = metadata.GetFieldDefinition((FieldDefinitionHandle)entity);
                return(fd.GetDeclaringType());

            case HandleKind.MethodDefinition:
                var md = metadata.GetMethodDefinition((MethodDefinitionHandle)entity);
                return(md.GetDeclaringType());

            case HandleKind.EventDefinition:
                var ed = metadata.GetEventDefinition((EventDefinitionHandle)entity);
                return(metadata.GetMethodDefinition(ed.GetAccessors().GetAny()).GetDeclaringType());

            case HandleKind.PropertyDefinition:
                var pd = metadata.GetPropertyDefinition((PropertyDefinitionHandle)entity);
                return(metadata.GetMethodDefinition(pd.GetAccessors().GetAny()).GetDeclaringType());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #3
0
        public MethodSemanticsLookup(MetadataReader metadata, MethodSemanticsAttributes filter = csharpAccessors)
        {
            if ((filter & MethodSemanticsAttributes.Other) != 0)
            {
                throw new NotSupportedException("SRM doesn't provide access to 'other' accessors");
            }
            entries = new List <Entry>(metadata.GetTableRowCount(TableIndex.MethodSemantics));
            foreach (var propHandle in metadata.PropertyDefinitions)
            {
                var prop      = metadata.GetPropertyDefinition(propHandle);
                var accessors = prop.GetAccessors();
                AddEntry(MethodSemanticsAttributes.Getter, accessors.Getter, propHandle);
                AddEntry(MethodSemanticsAttributes.Setter, accessors.Setter, propHandle);
            }
            foreach (var eventHandle in metadata.EventDefinitions)
            {
                var ev        = metadata.GetEventDefinition(eventHandle);
                var accessors = ev.GetAccessors();
                AddEntry(MethodSemanticsAttributes.Adder, accessors.Adder, eventHandle);
                AddEntry(MethodSemanticsAttributes.Remover, accessors.Remover, eventHandle);
                AddEntry(MethodSemanticsAttributes.Raiser, accessors.Raiser, eventHandle);
            }
            entries.Sort();

            void AddEntry(MethodSemanticsAttributes semantics, MethodDefinitionHandle method, EntityHandle association)
            {
                if ((semantics & filter) == 0 || method.IsNil)
                {
                    return;
                }
                entries.Add(new Entry(semantics, method, association));
            }
        }
コード例 #4
0
        private static void ProcessEventDef(EventDefinitionHandle eventDefHandle, MetadataReader dllReader, MetadataReader pdbReader, HashSet <DocumentHandle> docList)
        {
            var eventDef  = dllReader.GetEventDefinition(eventDefHandle);
            var accessors = eventDef.GetAccessors();

            if (!accessors.Adder.IsNil)
            {
                ProcessMethodDef(accessors.Adder, dllReader, pdbReader, docList, processDeclaringType: true);
            }

            if (!accessors.Remover.IsNil)
            {
                ProcessMethodDef(accessors.Remover, dllReader, pdbReader, docList, processDeclaringType: true);
            }

            if (!accessors.Raiser.IsNil)
            {
                ProcessMethodDef(accessors.Raiser, dllReader, pdbReader, docList, processDeclaringType: true);
            }

            foreach (var other in accessors.Others)
            {
                ProcessMethodDef(other, dllReader, pdbReader, docList, processDeclaringType: true);
            }
        }
コード例 #5
0
ファイル: EventTableTreeNode.cs プロジェクト: luiz117/ILSpy
 public EventDefEntry(PEFile module, EventDefinitionHandle handle)
 {
     this.metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
     this.module         = module;
     this.metadata       = module.Metadata;
     this.handle         = handle;
     this.eventDef       = metadata.GetEventDefinition(handle);
 }
コード例 #6
0
        public static void AddDependenciesDueToCustomAttributes(ref DependencyList dependencies, NodeFactory factory, EcmaMethod method)
        {
            MetadataReader         reader       = method.MetadataReader;
            MethodDefinitionHandle methodHandle = method.Handle;
            MethodDefinition       methodDef    = reader.GetMethodDefinition(methodHandle);

            // Handle custom attributes on the method
            AddDependenciesDueToCustomAttributes(ref dependencies, factory, method.Module, methodDef.GetCustomAttributes());

            // Handle custom attributes on method parameters
            foreach (ParameterHandle parameterHandle in methodDef.GetParameters())
            {
                Parameter parameter = reader.GetParameter(parameterHandle);
                AddDependenciesDueToCustomAttributes(ref dependencies, factory, method.Module, parameter.GetCustomAttributes());
            }

            // Handle custom attributes on generic method parameters
            foreach (GenericParameterHandle genericParameterHandle in methodDef.GetGenericParameters())
            {
                GenericParameter parameter = reader.GetGenericParameter(genericParameterHandle);
                AddDependenciesDueToCustomAttributes(ref dependencies, factory, method.Module, parameter.GetCustomAttributes());
            }

            // We don't model properties and events as separate entities within the compiler, so ensuring
            // we can generate custom attributes for the associated events and properties from here
            // is as good as any other place.
            //
            // As a performance optimization, we look for associated events and properties only
            // if the method is SpecialName. This is required for CLS compliance and compilers we
            // care about emit accessors like this.
            if ((methodDef.Attributes & MethodAttributes.SpecialName) != 0)
            {
                TypeDefinition declaringType = reader.GetTypeDefinition(methodDef.GetDeclaringType());

                foreach (PropertyDefinitionHandle propertyHandle in declaringType.GetProperties())
                {
                    PropertyDefinition property  = reader.GetPropertyDefinition(propertyHandle);
                    PropertyAccessors  accessors = property.GetAccessors();

                    if (accessors.Getter == methodHandle || accessors.Setter == methodHandle)
                    {
                        AddDependenciesDueToCustomAttributes(ref dependencies, factory, method.Module, property.GetCustomAttributes());
                    }
                }

                foreach (EventDefinitionHandle eventHandle in declaringType.GetEvents())
                {
                    EventDefinition @event    = reader.GetEventDefinition(eventHandle);
                    EventAccessors  accessors = @event.GetAccessors();

                    if (accessors.Adder == methodHandle || accessors.Remover == methodHandle || accessors.Raiser == methodHandle)
                    {
                        AddDependenciesDueToCustomAttributes(ref dependencies, factory, method.Module, @event.GetCustomAttributes());
                    }
                }
            }
        }
        internal sealed override IEnumerable <EventInfo> CoreGetDeclaredEvents(NameFilter optionalNameFilter, RuntimeTypeInfo reflectedType, RuntimeTypeInfo contextTypeInfo)
        {
            MetadataReader reader = Reader;

            foreach (EventDefinitionHandle eventHandle in DeclaredEventHandles)
            {
                if (optionalNameFilter == null || optionalNameFilter.Matches(reader.GetEventDefinition(eventHandle).Name, reader))
                {
                    yield return(EcmaFormatRuntimeEventInfo.GetRuntimeEventInfo(eventHandle, this, contextTypeInfo, reflectedType));
                }
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: tunnelvisionlabs/vsxdeps
        private static void Main(string[] args)
        {
            string assemblyPath = args[0];

            using (PEReader peReader = new PEReader(File.OpenRead(assemblyPath), PEStreamOptions.PrefetchMetadata))
            {
                ISet <AssemblyName> exposedDependencies = new HashSet <AssemblyName>(new AssemblyNameEqualityComparer());

                MetadataReader metadataReader = peReader.GetMetadataReader();
                foreach (var type in metadataReader.TypeDefinitions)
                {
                    TypeDefinition typeDefinition = metadataReader.GetTypeDefinition(type);
                    if (!IsExposedType(metadataReader, typeDefinition))
                    {
                        continue;
                    }

                    Console.WriteLine("Exposed type: {0}", GetFullName(metadataReader, typeDefinition));

                    CheckType(metadataReader, typeDefinition, exposedDependencies);

                    foreach (var eventDefinitionHandle in typeDefinition.GetEvents())
                    {
                        CheckEvent(metadataReader, metadataReader.GetEventDefinition(eventDefinitionHandle), exposedDependencies);
                    }

                    foreach (var methodDefinitionHandle in typeDefinition.GetMethods())
                    {
                        CheckMethod(metadataReader, metadataReader.GetMethodDefinition(methodDefinitionHandle), exposedDependencies);
                    }

                    foreach (var propertyDefinitionHandle in typeDefinition.GetProperties())
                    {
                        CheckProperty(metadataReader, metadataReader.GetPropertyDefinition(propertyDefinitionHandle), exposedDependencies);
                    }

                    foreach (var fieldDefinitionHandle in typeDefinition.GetFields())
                    {
                        CheckField(metadataReader, metadataReader.GetFieldDefinition(fieldDefinitionHandle), exposedDependencies);
                    }
                }

                Console.WriteLine();
                Console.WriteLine("Exposed Dependencies ({0}):", Path.GetFileName(args[0]));
                foreach (AssemblyName dependency in exposedDependencies.OrderBy(i => i.FullName, StringComparer.OrdinalIgnoreCase))
                {
                    Console.WriteLine("  {0}", dependency.FullName);
                }
            }
        }
コード例 #9
0
        public override string GetEntityName(PEFile module, EntityHandle handle, bool fullName)
        {
            MetadataReader metadata = module.Metadata;

            switch (handle.Kind)
            {
            case HandleKind.TypeDefinition:
                return(ToCSharpString(metadata, (TypeDefinitionHandle)handle, fullName));

            case HandleKind.FieldDefinition:
                var fd            = metadata.GetFieldDefinition((FieldDefinitionHandle)handle);
                var declaringType = fd.GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(fd.Name));
                }
                return(metadata.GetString(fd.Name));

            case HandleKind.MethodDefinition:
                var md = metadata.GetMethodDefinition((MethodDefinitionHandle)handle);
                declaringType = md.GetDeclaringType();
                string methodName = metadata.GetString(md.Name);
                switch (methodName)
                {
                case ".ctor":
                case ".cctor":
                    var td = metadata.GetTypeDefinition(declaringType);
                    methodName = ReflectionHelper.SplitTypeParameterCountFromReflectionName(metadata.GetString(td.Name));
                    break;

                case "Finalize":
                    const MethodAttributes finalizerAttributes = (MethodAttributes.Virtual | MethodAttributes.Family | MethodAttributes.HideBySig);
                    if ((md.Attributes & finalizerAttributes) != finalizerAttributes)
                    {
                        goto default;
                    }
                    MethodSignature <IType> methodSignature = md.DecodeSignature(MetadataExtensions.MinimalSignatureTypeProvider, default);
                    if (methodSignature.GenericParameterCount != 0 || methodSignature.ParameterTypes.Length != 0)
                    {
                        goto default;
                    }
                    td         = metadata.GetTypeDefinition(declaringType);
                    methodName = "~" + ReflectionHelper.SplitTypeParameterCountFromReflectionName(metadata.GetString(td.Name));
                    break;

                default:
                    var genericParams = md.GetGenericParameters();
                    if (genericParams.Count > 0)
                    {
                        methodName += "<";
                        int i = 0;
                        foreach (var h in genericParams)
                        {
                            if (i > 0)
                            {
                                methodName += ",";
                            }
                            var gp = metadata.GetGenericParameter(h);
                            methodName += metadata.GetString(gp.Name);
                        }
                        methodName += ">";
                    }
                    break;
                }
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + methodName);
                }
                return(methodName);

            case HandleKind.EventDefinition:
                var ed = metadata.GetEventDefinition((EventDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(ed.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(ed.Name));
                }
                return(metadata.GetString(ed.Name));

            case HandleKind.PropertyDefinition:
                var pd = metadata.GetPropertyDefinition((PropertyDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(pd.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(pd.Name));
                }
                return(metadata.GetString(pd.Name));

            default:
                return(null);
            }
        }
コード例 #10
0
        public void SimpleSignatureProviderCoverage()
        {
            using (FileStream stream = File.OpenRead(AssemblyPathHelper.GetAssemblyLocation(typeof(SignaturesToDecode <>).GetTypeInfo().Assembly)))
                using (var peReader = new PEReader(stream))
                {
                    MetadataReader       reader     = peReader.GetMetadataReader();
                    var                  provider   = new DisassemblingTypeProvider();
                    TypeDefinitionHandle typeHandle = TestMetadataResolver.FindTestType(reader, typeof(SignaturesToDecode <>));
                    Assert.Equal("System.Reflection.Metadata.Decoding.Tests.SignatureDecoderTests/SignaturesToDecode`1", provider.GetTypeFromHandle(reader, genericContext: null, handle: typeHandle));

                    TypeDefinition type = reader.GetTypeDefinition(typeHandle);
                    Dictionary <string, string> expectedFields        = GetExpectedFieldSignatures();
                    ImmutableArray <string>     genericTypeParameters = type.GetGenericParameters().Select(h => reader.GetString(reader.GetGenericParameter(h).Name)).ToImmutableArray();

                    var genericTypeContext = new DisassemblingGenericContext(genericTypeParameters, ImmutableArray <string> .Empty);

                    foreach (var fieldHandle in type.GetFields())
                    {
                        FieldDefinition field     = reader.GetFieldDefinition(fieldHandle);
                        string          fieldName = reader.GetString(field.Name);
                        string          expected;
                        Assert.True(expectedFields.TryGetValue(fieldName, out expected), "Unexpected field: " + fieldName);
                        Assert.Equal(expected, field.DecodeSignature(provider, genericTypeContext));
                    }

                    Dictionary <string, string> expectedMethods = GetExpectedMethodSignatures();
                    foreach (var methodHandle in type.GetMethods())
                    {
                        MethodDefinition method = reader.GetMethodDefinition(methodHandle);

                        ImmutableArray <string> genericMethodParameters = method.GetGenericParameters().Select(h => reader.GetString(reader.GetGenericParameter(h).Name)).ToImmutableArray();
                        var genericMethodContext = new DisassemblingGenericContext(genericTypeParameters, genericMethodParameters);

                        string methodName = reader.GetString(method.Name);
                        string expected;
                        Assert.True(expectedMethods.TryGetValue(methodName, out expected), "Unexpected method: " + methodName);
                        MethodSignature <string> signature = method.DecodeSignature(provider, genericMethodContext);
                        Assert.True(signature.Header.Kind == SignatureKind.Method);

                        if (methodName.StartsWith("Generic"))
                        {
                            Assert.Equal(1, signature.GenericParameterCount);
                        }
                        else
                        {
                            Assert.Equal(0, signature.GenericParameterCount);
                        }

                        Assert.True(signature.GenericParameterCount <= 1 && (methodName != "GenericMethodParameter" || signature.GenericParameterCount == 1));
                        Assert.Equal(expected, provider.GetFunctionPointerType(signature));
                    }

                    Dictionary <string, string> expectedProperties = GetExpectedPropertySignatures();
                    foreach (var propertyHandle in type.GetProperties())
                    {
                        PropertyDefinition property     = reader.GetPropertyDefinition(propertyHandle);
                        string             propertyName = reader.GetString(property.Name);
                        string             expected;
                        Assert.True(expectedProperties.TryGetValue(propertyName, out expected), "Unexpected property: " + propertyName);
                        MethodSignature <string> signature = property.DecodeSignature(provider, genericTypeContext);
                        Assert.True(signature.Header.Kind == SignatureKind.Property);
                        Assert.Equal(expected, provider.GetFunctionPointerType(signature));
                    }

                    Dictionary <string, string> expectedEvents = GetExpectedEventSignatures();
                    foreach (var eventHandle in type.GetEvents())
                    {
                        EventDefinition @event    = reader.GetEventDefinition(eventHandle);
                        string          eventName = reader.GetString(@event.Name);
                        string          expected;
                        Assert.True(expectedEvents.TryGetValue(eventName, out expected), "Unexpected event: " + eventName);

                        Assert.Equal(expected, provider.GetTypeFromHandle(reader, genericTypeContext, @event.Type));
                    }

                    Assert.Equal($"[{CollectionsAssemblyName}]System.Collections.Generic.List`1<!T>", provider.GetTypeFromHandle(reader, genericTypeContext, handle: type.BaseType));
                }
        }
コード例 #11
0
ファイル: CSharpLanguage.cs プロジェクト: zyonet/ILSpy
        public override string GetEntityName(PEFile module, EntityHandle handle, bool fullName)
        {
            MetadataReader metadata = module.Metadata;

            switch (handle.Kind)
            {
            case HandleKind.TypeDefinition:
                return(ToCSharpString(metadata, (TypeDefinitionHandle)handle, fullName));

            case HandleKind.FieldDefinition:
                var fd            = metadata.GetFieldDefinition((FieldDefinitionHandle)handle);
                var declaringType = fd.GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(fd.Name));
                }
                return(metadata.GetString(fd.Name));

            case HandleKind.MethodDefinition:
                var md = metadata.GetMethodDefinition((MethodDefinitionHandle)handle);
                declaringType = md.GetDeclaringType();
                string methodName = metadata.GetString(md.Name);
                if (methodName == ".ctor" || methodName == ".cctor")
                {
                    var td = metadata.GetTypeDefinition(declaringType);
                    methodName = ReflectionHelper.SplitTypeParameterCountFromReflectionName(metadata.GetString(td.Name));
                }
                else
                {
                    var genericParams = md.GetGenericParameters();
                    if (genericParams.Count > 0)
                    {
                        methodName += "<";
                        int i = 0;
                        foreach (var h in genericParams)
                        {
                            if (i > 0)
                            {
                                methodName += ",";
                            }
                            var gp = metadata.GetGenericParameter(h);
                            methodName += metadata.GetString(gp.Name);
                        }
                        methodName += ">";
                    }
                }
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + methodName);
                }
                return(methodName);

            case HandleKind.EventDefinition:
                var ed = metadata.GetEventDefinition((EventDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(ed.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(ed.Name));
                }
                return(metadata.GetString(ed.Name));

            case HandleKind.PropertyDefinition:
                var pd = metadata.GetPropertyDefinition((PropertyDefinitionHandle)handle);
                declaringType = metadata.GetMethodDefinition(pd.GetAccessors().GetAny()).GetDeclaringType();
                if (fullName)
                {
                    return(ToCSharpString(metadata, declaringType, fullName) + "." + metadata.GetString(pd.Name));
                }
                return(metadata.GetString(pd.Name));

            default:
                return(null);
            }
        }
コード例 #12
0
        private Mapping <EventDefinitionHandle> MapEventDefinitionImpl(EventDefinitionHandle handle)
        {
            EventDefinition eventDefinition = _sourceMetadata.GetEventDefinition(handle);
            EventAccessors  accessors       = eventDefinition.GetAccessors();

            // events always have an adder method, so use that to find the declaring type
            MethodDefinition adderMethodDefinition = _sourceMetadata.GetMethodDefinition(accessors.Adder);
            Mapping <TypeDefinitionHandle> declaringTypeMapping = MapTypeDefinition(adderMethodDefinition.GetDeclaringType());

            if (declaringTypeMapping.Target.IsNil)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            // Make sure each of the accessors maps successfully. Only the raiser is optional.
            Mapping <MethodDefinitionHandle> adderMethodDefinitionMapping = MapMethodDefinition(accessors.Adder);

            if (adderMethodDefinitionMapping.Target.IsNil)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            Mapping <MethodDefinitionHandle> removerMethodDefinitionMapping = MapMethodDefinition(accessors.Remover);

            if (removerMethodDefinitionMapping.Target.IsNil)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            Mapping <MethodDefinitionHandle> raiserMethodDefinitionMapping = default(Mapping <MethodDefinitionHandle>);

            if (!accessors.Raiser.IsNil)
            {
                raiserMethodDefinitionMapping = MapMethodDefinition(accessors.Raiser);
                if (raiserMethodDefinitionMapping.Target.IsNil)
                {
                    return(new Mapping <EventDefinitionHandle>());
                }
            }

            // locate the target event by name
            string eventName = _sourceMetadata.GetString(eventDefinition.Name);
            EventDefinitionHandle targetEventDefinitionHandle = default(EventDefinitionHandle);
            EventDefinition       targetEventDefinition       = default(EventDefinition);

            foreach (var targetHandle in _targetMetadata.EventDefinitions)
            {
                targetEventDefinition = _targetMetadata.GetEventDefinition(targetHandle);
                MethodDefinition targetAdderMethodDefinition = _targetMetadata.GetMethodDefinition(targetEventDefinition.GetAccessors().Adder);
                if (targetAdderMethodDefinition.GetDeclaringType() != declaringTypeMapping.Target)
                {
                    continue;
                }

                if (!_targetMetadata.StringComparer.Equals(targetEventDefinition.Name, eventName))
                {
                    continue;
                }

                targetEventDefinitionHandle = targetHandle;
                break;
            }

            if (targetEventDefinitionHandle.IsNil)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            EventAccessors targetAccessors = targetEventDefinition.GetAccessors();

            if (targetAccessors.Adder != adderMethodDefinitionMapping.Target)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            if (targetAccessors.Remover != removerMethodDefinitionMapping.Target)
            {
                return(new Mapping <EventDefinitionHandle>());
            }

            if (!accessors.Raiser.IsNil)
            {
                if (targetAccessors.Raiser != raiserMethodDefinitionMapping.Target)
                {
                    return(new Mapping <EventDefinitionHandle>());
                }
            }

            return(new Mapping <EventDefinitionHandle>(targetEventDefinitionHandle));
        }
コード例 #13
0
 public static EventDefinition GetEventDefinition(this EventDefinitionHandle handle, MetadataReader reader) => reader.GetEventDefinition(handle);
コード例 #14
0
 public static StringHandle[] GetEventDefNames(this MetadataReader reader)
 {
     return(reader.EventDefinitions.Select(handle => reader.GetEventDefinition(handle).Name).ToArray());
 }
コード例 #15
0
ファイル: EntityToString.cs プロジェクト: saul/Refasmer
 public static string ToString(this MetadataReader reader, EventDefinitionHandle x) => reader.ToString(reader.GetEventDefinition(x));
コード例 #16
0
        /// <summary>
        /// EventMap Table Columns:
        ///     Parent (RID to TypeDef)
        ///     EventList (RID to EventTable)
        /// ===========================================
        /// Event Table Columns:
        ///     Name (offset to #String)
        ///     Flags (2 byte unsigned)
        ///     EventType (token to TypeDefOrRef)
        /// </summary>
        private void ValidateEvent(MetadataReader reader, uint rowId, uint startIdx, uint count, bool isVBMod = false)
        {
            if (0 == count)
            {
                return;
            }

            var expNames = new string[] { "E01", "E01", "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.E01" };

            // ModuleVB01
            // Map: 0:TypeDef[2000003], 1:Event[14000001]
            // Event: 0:0000, 1:string#1c6, 2:TypeDefOrRef[02000006]
            var modNames = new string[] { "AnEvent" };
            var modTokens = new uint[] { 0x02000006 };

            uint zeroBased = startIdx - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.EventTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            // Validity Rules
            Assert.InRange((uint)reader.EventTable.NumberOfRows, zeroBased + count, uint.MaxValue);
            for (uint i = zeroBased; i < zeroBased + count; i++)
            {
                var handle = EventDefinitionHandle.FromRowId((int)i + 1);
                var evnt = reader.GetEventDefinition(handle);

                // Name
                if (isVBMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(evnt.Name));
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(evnt.Name));
                }

                Assert.Equal(0, (ushort)evnt.Attributes);
                if (isVBMod)
                {
                    Assert.Equal(modTokens[i], (uint)evnt.Type.Token);
                }
                else
                {
                    Assert.Equal((int)rowId, evnt.Type.RowId); // could be TypeSpec Id if it's in generic
                }
            }
        }
コード例 #17
0
        internal void Resolve(TRequest request, RequestSignature signature)
        {
            QualifiedName           qualifiedTypeName;
            ImmutableArray <string> memberTypeParameters;

            GetNameAndTypeParameters(signature.MemberName, out qualifiedTypeName, out memberTypeParameters);

            var typeName         = qualifiedTypeName.Qualifier;
            var memberName       = qualifiedTypeName.Name;
            var memberParameters = signature.Parameters;

            var allTypeParameters = GetAllGenericTypeParameters(typeName);

            foreach (var typeHandle in _reader.TypeDefinitions)
            {
                var typeDef         = _reader.GetTypeDefinition(typeHandle);
                int containingArity = CompareToTypeDefinition(typeDef, typeName);
                if (containingArity < 0)
                {
                    continue;
                }

                // Visit methods.
                foreach (var methodHandle in typeDef.GetMethods())
                {
                    var methodDef = _reader.GetMethodDefinition(methodHandle);
                    if (!IsResolvableMethod(methodDef))
                    {
                        continue;
                    }
                    if (MatchesMethod(typeDef, methodDef, memberName, allTypeParameters, containingArity, memberTypeParameters, memberParameters))
                    {
                        OnFunctionResolved(request, methodHandle);
                    }
                }

                if (memberTypeParameters.IsEmpty)
                {
                    // Visit properties.
                    foreach (var propertyHandle in typeDef.GetProperties())
                    {
                        var propertyDef = _reader.GetPropertyDefinition(propertyHandle);
                        var accessors   = propertyDef.GetAccessors();
                        if (MatchesPropertyOrEvent(propertyDef.Name, accessors.Getter, memberName, allTypeParameters, containingArity, memberParameters))
                        {
                            OnAccessorResolved(request, accessors.Getter);
                            OnAccessorResolved(request, accessors.Setter);
                        }
                    }

                    // Visit events.
                    foreach (var eventHandle in typeDef.GetEvents())
                    {
                        var eventDef  = _reader.GetEventDefinition(eventHandle);
                        var accessors = eventDef.GetAccessors();

                        if (MatchesPropertyOrEvent(eventDef.Name, accessors.Adder, memberName, allTypeParameters, containingArity, memberParameters))
                        {
                            OnAccessorResolved(request, accessors.Adder);
                            OnAccessorResolved(request, accessors.Remover);
                        }
                    }
                }
            }
        }