Example #1
0
 //
 // methodHandle    - the "tkMethodDef" that identifies the method.
 // definingType   - the "tkTypeDef" that defined the method (this is where you get the metadata reader that created methodHandle.)
 // contextType    - the type that supplies the type context (i.e. substitutions for generic parameters.) Though you
 //                  get your raw information from "definingType", you report "contextType" as your DeclaringType property.
 //
 //  For example:
 //
 //       typeof(Foo<>).GetTypeInfo().DeclaredMembers
 //
 //           The definingType and contextType are both Foo<>
 //
 //       typeof(Foo<int,String>).GetTypeInfo().DeclaredMembers
 //
 //          The definingType is "Foo<,>"
 //          The contextType is "Foo<int,String>"
 //
 //  We don't report any DeclaredMembers for arrays or generic parameters so those don't apply.
 //
 public RuntimeMethodCommon(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _definingTypeInfo = definingTypeInfo;
     _methodHandle = methodHandle;
     _contextTypeInfo = contextTypeInfo;
     _reader = definingTypeInfo.Reader;
     _method = methodHandle.GetMethod(_reader);
 }
        } // GetMemberReference

        public Method GetMethod(MethodHandle handle)
        {
            var record = new Method() { _reader = this, _handle = handle };
            var offset = (uint)handle.Offset;
            offset = _streamReader.Read(offset, out record._flags);
            offset = _streamReader.Read(offset, out record._implFlags);
            offset = _streamReader.Read(offset, out record._name);
            offset = _streamReader.Read(offset, out record._signature);
            offset = _streamReader.Read(offset, out record._parameters);
            offset = _streamReader.Read(offset, out record._genericParameters);
            offset = _streamReader.Read(offset, out record._customAttributes);
            return record;
        } // GetMethod
        // This is specially designed for a hot path so we make some compromises in the signature:
        //
        //     - "method" is passed by reference even though no side-effects are intended.
        //
        public static bool IsConstructor(ref Method method, MetadataReader reader)
        {
            if ((method.Flags & (MethodAttributes.RTSpecialName | MethodAttributes.SpecialName)) != (MethodAttributes.RTSpecialName | MethodAttributes.SpecialName))
                return false;

            ConstantStringValueHandle nameHandle = method.Name;
            return nameHandle.StringEquals(ConstructorInfo.ConstructorName, reader) || nameHandle.StringEquals(ConstructorInfo.TypeConstructorName, reader);
        }