private NativeFormatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, QTypeDefRefOrSpec qualifiedParameterTypeHandle, TypeContext typeContext)
     : base(member, position, qualifiedParameterTypeHandle, typeContext)
 {
     _methodHandle = methodHandle;
     _parameterHandle = parameterHandle;
     _parameter = parameterHandle.GetParameter(Reader);
 }
 private RuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reader, typeHandle, typeContext)
 {
     _methodHandle = methodHandle;
     _parameterHandle = parameterHandle;
     _parameter = parameterHandle.GetParameter(reader);
 }
Beispiel #3
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);
 }
Beispiel #4
0
        private TypeDesc[] _genericParameters; // TODO: Optional field?

        internal NativeFormatMethod(NativeFormatType type, MethodHandle handle)
        {
            _type = type;
            _handle = handle;

#if DEBUG
            // Initialize name eagerly in debug builds for convenience
            this.ToString();
#endif
        }
 public static bool TryGetMethodInvokeMetadata(
     MetadataReader metadataReader,
     RuntimeTypeHandle declaringTypeHandle,
     MethodHandle methodHandle,
     RuntimeTypeHandle[] genericMethodTypeArgumentHandles,
     ref MethodSignatureComparer methodSignatureComparer,
     CanonicalFormKind canonFormKind,
     out MethodInvokeMetadata methodInvokeMetadata)
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
        public unsafe static void TestCommonTailOptimization()
        {
            var wr = new Writer.MetadataWriter();

            wr.ScopeDefinitions.Add(BuildSimpleTestData());
            var ms = new MemoryStream();

            wr.Write(ms);

            fixed(byte *pBuffer = ms.ToArray())
            {
                var rd = new Reader.MetadataReader((IntPtr)pBuffer, (int)ms.Length);

                Reader.ScopeDefinitionHandle scopeHandle        = rd.ScopeDefinitions.Single();
                Reader.ScopeDefinition       systemRuntimeScope = scopeHandle.GetScopeDefinition(rd);
                Reader.NamespaceDefinition   rootNamespace      = systemRuntimeScope.RootNamespaceDefinition.GetNamespaceDefinition(rd);
                Reader.NamespaceDefinition   systemNamespace    =
                    rootNamespace.NamespaceDefinitions.Single(
                        ns => ns.GetNamespaceDefinition(rd).Name.StringEquals("System", rd)
                        ).GetNamespaceDefinition(rd);

                // This validates the common tail optimization.
                // Since both System.Object and System.String define a default constructor and the
                // records are structurally equivalent, there should only be one metadata record
                // representing a default .ctor in the blob.
                Reader.TypeDefinition objectType = systemNamespace.TypeDefinitions.Single(
                    t => t.GetTypeDefinition(rd).Name.StringEquals("Object", rd)
                    ).GetTypeDefinition(rd);
                Reader.TypeDefinition stringType = systemNamespace.TypeDefinitions.Single(
                    t => t.GetTypeDefinition(rd).Name.StringEquals("String", rd)
                    ).GetTypeDefinition(rd);

                Reader.MethodHandle objectCtor = objectType.Methods.Single();
                Reader.MethodHandle stringCtor = stringType.Methods.Single();

                Assert.True(objectCtor.Equals(stringCtor));
            }
        }
Beispiel #7
0
 //==============================================================================================
 // Invoke and field access support.
 //==============================================================================================
 public abstract MethodInvoker TryGetMethodInvoker(MetadataReader reader, RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles);
Beispiel #8
0
        //==============================================================================================
        // Non-public methods
        //==============================================================================================
        internal MethodInvoker GetMethodInvoker(MetadataReader reader, RuntimeTypeInfo declaringType, MethodHandle methodHandle, RuntimeTypeInfo[] genericMethodTypeArguments, MemberInfo exceptionPertainant)
        {
            if (declaringType.ContainsGenericParameters)
                return new OpenMethodInvoker();
            for (int i = 0; i < genericMethodTypeArguments.Length; i++)
            {
                if (genericMethodTypeArguments[i].ContainsGenericParameters)
                    return new OpenMethodInvoker();
            }

            RuntimeTypeHandle typeDefinitionHandle = declaringType.TypeHandle;
            RuntimeTypeHandle[] genericMethodTypeArgumentHandles = new RuntimeTypeHandle[genericMethodTypeArguments.Length];

            for (int i = 0; i < genericMethodTypeArguments.Length; i++)
            {
                genericMethodTypeArgumentHandles[i] = genericMethodTypeArguments[i].TypeHandle;
            }
            MethodInvoker methodInvoker = TryGetMethodInvoker(reader, typeDefinitionHandle, methodHandle, genericMethodTypeArgumentHandles);
            if (methodInvoker == null)
                throw ReflectionCoreExecution.ExecutionDomain.CreateNonInvokabilityException(exceptionPertainant);
            return methodInvoker;
        }
 //
 // 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.
 //
 private RuntimeNamedMethodInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
     : base()
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
        private bool GetAccessor(MethodSemanticsAttributes methodSemanticsAttribute, out MethodHandle methodHandle)
        {
            bool inherited = !_reflectedType.Equals(_contextTypeInfo);

            foreach (MethodSemanticsHandle methodSemanticsHandle in _property.MethodSemantics)
            {
                MethodSemantics methodSemantics = methodSemanticsHandle.GetMethodSemantics(_reader);
                if (methodSemantics.Attributes == methodSemanticsAttribute)
                {
                    methodHandle = methodSemantics.Method;

                    if (inherited)
                    {
                        MethodAttributes flags = methodHandle.GetMethod(_reader).Flags;
                        if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                            continue;
                    }

                    return true;
                }
            }
            methodHandle = default(MethodHandle);
            return false;
        }
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out MethodHandle handle)
        {
            uint value;
            offset = reader.DecodeUnsigned(offset, out value);
            handle = new MethodHandle((int)value);
            handle._Validate();
            return offset;
        } // Read
Beispiel #12
0
 public abstract bool TryGetMethodFromHandleAndType(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle, out MethodHandle methodHandle, out RuntimeTypeHandle[] genericMethodTypeArgumentHandles);
Beispiel #13
0
 private bool GetAccessor(MethodSemanticsAttributes methodSemanticsAttribute, out MethodHandle methodHandle)
 {
     foreach (MethodSemanticsHandle methodSemanticsHandle in _property.MethodSemantics)
     {
         MethodSemantics methodSemantics = methodSemanticsHandle.GetMethodSemantics(_reader);
         if (methodSemantics.Attributes == methodSemanticsAttribute)
         {
             methodHandle = methodSemantics.Method;
             return true;
         }
     }
     methodHandle = default(MethodHandle);
     return false;
 }
Beispiel #14
0
 //
 // Retrieves the MethodBase for a given method handle. Helper to implement Delegate.GetMethodInfo()
 //
 public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles)
 {
     RuntimeTypeInfo contextTypeInfo = declaringTypeHandle.GetTypeForRuntimeTypeHandle();
     RuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers;
     MetadataReader reader = definingTypeInfo.Reader;
     if (methodHandle.IsConstructor(reader))
     {
         return RuntimePlainConstructorInfo.GetRuntimePlainConstructorInfo(methodHandle, definingTypeInfo, contextTypeInfo);
     }
     else
     {
         RuntimeNamedMethodInfo runtimeNamedMethodInfo = RuntimeNamedMethodInfo.GetRuntimeNamedMethodInfo(methodHandle, definingTypeInfo, contextTypeInfo);
         if (!runtimeNamedMethodInfo.IsGenericMethod)
         {
             return runtimeNamedMethodInfo;
         }
         else
         {
             RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[genericMethodTypeArgumentHandles.Length];
             for (int i = 0; i < genericMethodTypeArgumentHandles.Length; i++)
             {
                 genericTypeArguments[i] = genericMethodTypeArgumentHandles[i].GetTypeForRuntimeTypeHandle();
             }
             return RuntimeConstructedGenericMethodInfo.GetRuntimeConstructedGenericMethodInfo(runtimeNamedMethodInfo, genericTypeArguments);
         }
     }
 }
Beispiel #15
0
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out MethodHandle[] values)
        {
            uint count;
            offset = reader.DecodeUnsigned(offset, out count);
            #if !NETFX_45
            if (count == 0)
            {
                values = Array.Empty<MethodHandle>();
            }
            else
            #endif
            {
                values = new MethodHandle[count];
                for (uint i = 0; i < count; ++i)
                {
                    MethodHandle tmp;
                    offset = reader.Read(offset, out tmp);
                    values[i] = tmp;
                }
            }
            return offset;
        } // Read
Beispiel #16
0
 public abstract IEnumerable<CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, MethodHandle methodHandle, TypeDefinitionHandle declaringTypeHandle);
Beispiel #17
0
 public abstract IEnumerable<CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, ParameterHandle parameterHandle, MethodHandle declaringMethodHandle);
        } // Equals

        public bool Equals(MethodHandle handle)
        {
            return _value == handle._value;
        } // Equals
 //
 // 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.
 //
 private RuntimePlainConstructorInfo(MethodHandle methodHandle, RuntimeNamedTypeInfo definingTypeInfo, RuntimeTypeInfo contextTypeInfo)
 {
     _common = new RuntimeMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo);
 }
        } // 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
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out MethodHandle[] values)
        {
            uint count;
            offset = reader.DecodeUnsigned(offset, out count);
            if (count == 0)
            {
                values = s_emptyMethodHandleArray;
            }
            else
            {
                values = new MethodHandle[count];
                for (uint i = 0; i < count; ++i)
                {
                    MethodHandle tmp;
                    offset = reader.Read(offset, out tmp);
                    values[i] = tmp;
                }
            }
            return offset;
        } // Read
        } // ToHandle

        internal Handle ToHandle(MethodHandle handle)
        {
            return new Handle(handle._value);
        } // ToHandle
        } // IsNull

        internal bool IsNull(MethodHandle handle)
        {
            return (handle._value & 0x00FFFFFF) == 0;
        } // IsNull
Beispiel #24
0
 //
 // Retrieves the MethodBase for a given method handle. Helper to implement Delegate.GetMethodInfo()
 //
 public MethodBase GetMethod(RuntimeTypeHandle declaringTypeHandle, MethodHandle methodHandle, RuntimeTypeHandle[] genericMethodTypeArgumentHandles)
 {
     RuntimeTypeInfo contextTypeInfo = declaringTypeHandle.GetTypeForRuntimeTypeHandle();
     NativeFormatRuntimeNamedTypeInfo definingTypeInfo = contextTypeInfo.AnchoringTypeDefinitionForDeclaredMembers.CastToNativeFormatRuntimeNamedTypeInfo();
     MetadataReader reader = definingTypeInfo.Reader;
     if (methodHandle.IsConstructor(reader))
     {
         return RuntimePlainConstructorInfo<NativeFormatMethodCommon>.GetRuntimePlainConstructorInfo(new NativeFormatMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo));
     }
     else
     {
         // RuntimeMethodHandles always yield methods whose ReflectedType is the DeclaringType.
         RuntimeTypeInfo reflectedType = contextTypeInfo;
         RuntimeNamedMethodInfo<NativeFormatMethodCommon> runtimeNamedMethodInfo = RuntimeNamedMethodInfo<NativeFormatMethodCommon>.GetRuntimeNamedMethodInfo(new NativeFormatMethodCommon(methodHandle, definingTypeInfo, contextTypeInfo), reflectedType);
         if (!runtimeNamedMethodInfo.IsGenericMethod)
         {
             return runtimeNamedMethodInfo;
         }
         else
         {
             RuntimeTypeInfo[] genericTypeArguments = new RuntimeTypeInfo[genericMethodTypeArgumentHandles.Length];
             for (int i = 0; i < genericMethodTypeArgumentHandles.Length; i++)
             {
                 genericTypeArguments[i] = genericMethodTypeArgumentHandles[i].GetTypeForRuntimeTypeHandle();
             }
             return RuntimeConstructedGenericMethodInfo.GetRuntimeConstructedGenericMethodInfo(runtimeNamedMethodInfo, genericTypeArguments);
         }
     }
 }