Beispiel #1
0
        internal static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeTypeHandle declaredTypeHandle, RuntimeTypeHandle reflectedTypeHandle)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }
            bool flag = !declaredTypeHandle.Equals(reflectedTypeHandle);
            RuntimeMethodHandle methodHandle = declaredTypeHandle.GetModuleHandle().ResolveMethodHandle(tkMethod, declaredTypeHandle.GetInstantiation(), new RuntimeTypeHandle[0]);
            MethodAttributes    attributes   = methodHandle.GetAttributes();
            bool flag2 = (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
            bool flag3 = (attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope;

            if (flag)
            {
                if (flag2)
                {
                    return(null);
                }
                if (flag3 && ((declaredTypeHandle.GetAttributes() & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass))
                {
                    int slot = methodHandle.GetSlot();
                    methodHandle = reflectedTypeHandle.GetMethodAt(slot);
                }
            }
            MethodAttributes  attributes2 = attributes & MethodAttributes.MemberAccessMask;
            RuntimeMethodInfo methodBase  = RuntimeType.GetMethodBase(reflectedTypeHandle, methodHandle) as RuntimeMethodInfo;

            if (methodBase == null)
            {
                methodBase = reflectedTypeHandle.GetRuntimeType().Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
            }
            return(methodBase);
        }
Beispiel #2
0
        [System.Security.SecurityCritical]  // auto-generated
        internal RuntimeConstructorInfo(
            RuntimeMethodHandleInternal handle, RuntimeType declaringType, RuntimeTypeCache reflectedTypeCache,
            MethodAttributes methodAttributes, BindingFlags bindingFlags)
        {
            Contract.Ensures(methodAttributes == RuntimeMethodHandle.GetAttributes(handle));

            m_bindingFlags       = bindingFlags;
            m_reflectedTypeCache = reflectedTypeCache;
            m_declaringType      = declaringType;
            m_handle             = handle.Value;
            m_methodAttributes   = methodAttributes;
        }
Beispiel #3
0
        internal RuntimeMethodInfo(
            RuntimeMethodHandleInternal handle, RuntimeType declaringType,
            RuntimeTypeCache reflectedTypeCache, MethodAttributes methodAttributes, BindingFlags bindingFlags, object keepalive)
        {
            Debug.Assert(!handle.IsNullHandle());
            Debug.Assert(methodAttributes == RuntimeMethodHandle.GetAttributes(handle));

            m_bindingFlags       = bindingFlags;
            m_declaringType      = declaringType;
            m_keepalive          = keepalive;
            m_handle             = handle.Value;
            m_reflectedTypeCache = reflectedTypeCache;
            m_methodAttributes   = methodAttributes;
        }
        private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }
            bool flag = declaredType != reflectedType;

            IntPtr[] array         = null;
            int      typeInstCount = 0;

            RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal();
            if (instantiationInternal != null)
            {
                typeInstCount = instantiationInternal.Length;
                array         = new IntPtr[instantiationInternal.Length];
                for (int i = 0; i < instantiationInternal.Length; i++)
                {
                    array[i] = instantiationInternal[i].GetTypeHandleInternal().Value;
                }
            }
            RuntimeMethodHandleInternal runtimeMethodHandleInternal = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, array, typeInstCount, null, 0);

            if (flag)
            {
                MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(runtimeMethodHandleInternal);
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                {
                    return(null);
                }
                if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope)
                {
                    bool flag2 = (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.NotPublic;
                    if (flag2)
                    {
                        int slot = RuntimeMethodHandle.GetSlot(runtimeMethodHandleInternal);
                        runtimeMethodHandleInternal = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                    }
                }
            }
            RuntimeMethodInfo runtimeMethodInfo = RuntimeType.GetMethodBase(reflectedType, runtimeMethodHandleInternal) as RuntimeMethodInfo;

            if (runtimeMethodInfo == null)
            {
                runtimeMethodInfo = (reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo);
            }
            return(runtimeMethodInfo);
        }
Beispiel #5
0
        private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }
            bool flag = declaredType != reflectedType;

            IntPtr[] typeInstantiationContext = null;
            int      typeInstCount            = 0;

            RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal();
            if (instantiationInternal != null)
            {
                typeInstCount            = instantiationInternal.Length;
                typeInstantiationContext = new IntPtr[instantiationInternal.Length];
                for (int i = 0; i < instantiationInternal.Length; i++)
                {
                    typeInstantiationContext[i] = instantiationInternal[i].GetTypeHandleInternal().Value;
                }
            }
            RuntimeMethodHandleInternal method = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, null, 0);

            if (flag)
            {
                MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(method);
                if ((attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                {
                    return(null);
                }
                if (((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope) && ((RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.AnsiClass))
                {
                    int slot = RuntimeMethodHandle.GetSlot(method);
                    method = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                }
            }
            RuntimeMethodInfo methodBase = RuntimeType.GetMethodBase(reflectedType, method) as RuntimeMethodInfo;

            if (methodBase == null)
            {
                methodBase = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
            }
            return(methodBase);
        }
Beispiel #6
0
        private static RuntimeMethodInfo AssignAssociates(int tkMethod, RuntimeType declaredType, RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return((RuntimeMethodInfo)null);
            }
            bool flag = declaredType != reflectedType;

            IntPtr[] typeInstantiationContext = (IntPtr[])null;
            int      typeInstCount            = 0;

            RuntimeType[] instantiationInternal = declaredType.GetTypeHandleInternal().GetInstantiationInternal();
            if (instantiationInternal != null)
            {
                typeInstCount            = instantiationInternal.Length;
                typeInstantiationContext = new IntPtr[instantiationInternal.Length];
                for (int index = 0; index < instantiationInternal.Length; ++index)
                {
                    typeInstantiationContext[index] = instantiationInternal[index].GetTypeHandleInternal().Value;
                }
            }
            RuntimeMethodHandleInternal methodHandleInternal = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, typeInstantiationContext, typeInstCount, (IntPtr[])null, 0);

            if (flag)
            {
                MethodAttributes attributes = RuntimeMethodHandle.GetAttributes(methodHandleInternal);
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && (attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                {
                    return((RuntimeMethodInfo)null);
                }
                if ((attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope && (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.NotPublic)
                {
                    int slot = RuntimeMethodHandle.GetSlot(methodHandleInternal);
                    methodHandleInternal = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                }
            }
            RuntimeMethodInfo runtimeMethodInfo = RuntimeType.GetMethodBase(reflectedType, methodHandleInternal) as RuntimeMethodInfo;

            if ((MethodInfo)runtimeMethodInfo == (MethodInfo)null)
            {
                runtimeMethodInfo = reflectedType.Module.ResolveMethod(tkMethod, (Type[])null, (Type[])null) as RuntimeMethodInfo;
            }
            return(runtimeMethodInfo);
        }
Beispiel #7
0
        private static RuntimeMethodInfo?AssignAssociates(
            int tkMethod,
            RuntimeType declaredType,
            RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }

            Debug.Assert(declaredType != null);
            Debug.Assert(reflectedType != null);

            bool isInherited = declaredType != reflectedType;

            Span <IntPtr> genericArgumentHandles = stackalloc IntPtr[0];

            RuntimeType[] genericArguments = declaredType.TypeHandle.GetInstantiationInternal();
            if (genericArguments != null)
            {
                genericArgumentHandles = genericArguments.Length <= 16 ? // arbitrary stackalloc limit
                                         stackalloc IntPtr[genericArguments.Length] :
                                         new IntPtr[genericArguments.Length];
                for (int i = 0; i < genericArguments.Length; i++)
                {
                    genericArgumentHandles[i] = genericArguments[i].TypeHandle.Value;
                }
            }

            RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternal(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, default);

            Debug.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token");

            if (isInherited)
            {
                MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle);

                // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility
                // (ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled  [CLS]"
                // Consequently, a property may be composed of public and private methods. If the declared type !=
                // the reflected type, the private methods should not be exposed. Note that this implies that the
                // identity of a property includes it's reflected type.

                if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                {
                    return(null);
                }

                // Note this is the first time the property was encountered walking from the most derived class
                // towards the base class. It would seem to follow that any associated methods would not
                // be overriden -- but this is not necessarily true. A more derived class may have overriden a
                // virtual method associated with a property in a base class without associating the override with
                // the same or any property in the derived class.
                if ((methAttr & MethodAttributes.Virtual) != 0)
                {
                    bool declaringTypeIsClass =
                        (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class;

                    // It makes no sense to search for a virtual override of a method declared on an interface.
                    if (declaringTypeIsClass)
                    {
                        int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle);

                        // Find the override visible from the reflected type
                        associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                    }
                }
            }

            RuntimeMethodInfo?associateMethod =
                RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo;

            // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle
            return(associateMethod ?? reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo);
        }
Beispiel #8
0
        [System.Security.SecurityCritical]  // auto-generated
        private static unsafe RuntimeMethodInfo AssignAssociates(
            int tkMethod,
            RuntimeType declaredType,
            RuntimeType reflectedType)
        {
            if (MetadataToken.IsNullToken(tkMethod))
            {
                return(null);
            }

            Contract.Assert(declaredType != null);
            Contract.Assert(reflectedType != null);

            bool isInherited = declaredType != reflectedType;

            IntPtr[] genericArgumentHandles = null;
            int      genericArgumentCount   = 0;

            RuntimeType [] genericArguments = declaredType.GetTypeHandleInternal().GetInstantiationInternal();
            if (genericArguments != null)
            {
                genericArgumentCount   = genericArguments.Length;
                genericArgumentHandles = new IntPtr[genericArguments.Length];
                for (int i = 0; i < genericArguments.Length; i++)
                {
                    genericArgumentHandles[i] = genericArguments[i].GetTypeHandleInternal().Value;
                }
            }

            RuntimeMethodHandleInternal associateMethodHandle = ModuleHandle.ResolveMethodHandleInternalCore(RuntimeTypeHandle.GetModule(declaredType), tkMethod, genericArgumentHandles, genericArgumentCount, null, 0);

            Contract.Assert(!associateMethodHandle.IsNullHandle(), "Failed to resolve associateRecord methodDef token");

            if (isInherited)
            {
                MethodAttributes methAttr = RuntimeMethodHandle.GetAttributes(associateMethodHandle);

                // ECMA MethodSemantics: "All methods for a given Property or Event shall have the same accessibility
                //(ie the MemberAccessMask subfield of their Flags row) and cannot be CompilerControlled  [CLS]"
                // Consequently, a property may be composed of public and private methods. If the declared type !=
                // the reflected type, the private methods should not be exposed. Note that this implies that the
                // identity of a property includes it's reflected type.

                // NetCF actually includes private methods from parent classes in Reflection results
                // We will mimic that in Mango Compat mode.
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                {
                    if ((methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private)
                    {
                        return(null);
                    }
                }

                // Note this is the first time the property was encountered walking from the most derived class
                // towards the base class. It would seem to follow that any associated methods would not
                // be overriden -- but this is not necessarily true. A more derived class may have overriden a
                // virtual method associated with a property in a base class without associating the override with
                // the same or any property in the derived class.
                if ((methAttr & MethodAttributes.Virtual) != 0)
                {
                    bool declaringTypeIsClass =
                        (RuntimeTypeHandle.GetAttributes(declaredType) & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class;

                    // It makes no sense to search for a virtual override of a method declared on an interface.
                    if (declaringTypeIsClass)
                    {
                        int slot = RuntimeMethodHandle.GetSlot(associateMethodHandle);

                        // Find the override visible from the reflected type
                        associateMethodHandle = RuntimeTypeHandle.GetMethodAt(reflectedType, slot);
                    }
                }
            }

            RuntimeMethodInfo associateMethod =
                RuntimeType.GetMethodBase(reflectedType, associateMethodHandle) as RuntimeMethodInfo;

            // suppose a property was mapped to a method not in the derivation hierarchy of the reflectedTypeHandle
            if (associateMethod == null)
            {
                associateMethod = reflectedType.Module.ResolveMethod(tkMethod, null, null) as RuntimeMethodInfo;
            }

            return(associateMethod);
        }