Inheritance: MethodInfo, ISerializable, IRuntimeMethodInfo
Example #1
0
 public RuntimePropertyInfo(Property property, RuntimeType declaringType, RuntimeMethodInfo getMethod, RuntimeMethodInfo setMethod)
 {
     _property = property;
     _declaringType = declaringType;
     _getMethod = getMethod;
     _setMethod = setMethod;
 }
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            string str;
            if ((method.Attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PrivateScope)
            {
                return null;
            }
            MetadataImport metadataImport = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
            string importDll = null;
            int metadataToken = method.MetadataToken;
            PInvokeAttributes bestFitUseAssem = PInvokeAttributes.BestFitUseAssem;
            metadataImport.GetPInvokeMap(metadataToken, out bestFitUseAssem, out str, out importDll);
            System.Runtime.InteropServices.CharSet none = System.Runtime.InteropServices.CharSet.None;
            switch ((bestFitUseAssem & PInvokeAttributes.CharSetAuto))
            {
                case PInvokeAttributes.BestFitUseAssem:
                    none = System.Runtime.InteropServices.CharSet.None;
                    break;

                case PInvokeAttributes.CharSetAnsi:
                    none = System.Runtime.InteropServices.CharSet.Ansi;
                    break;

                case PInvokeAttributes.CharSetUnicode:
                    none = System.Runtime.InteropServices.CharSet.Unicode;
                    break;

                case PInvokeAttributes.CharSetAuto:
                    none = System.Runtime.InteropServices.CharSet.Auto;
                    break;
            }
            System.Runtime.InteropServices.CallingConvention cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
            switch ((bestFitUseAssem & PInvokeAttributes.CallConvMask))
            {
                case PInvokeAttributes.CallConvStdcall:
                    cdecl = System.Runtime.InteropServices.CallingConvention.StdCall;
                    break;

                case PInvokeAttributes.CallConvThiscall:
                    cdecl = System.Runtime.InteropServices.CallingConvention.ThisCall;
                    break;

                case PInvokeAttributes.CallConvFastcall:
                    cdecl = System.Runtime.InteropServices.CallingConvention.FastCall;
                    break;

                case PInvokeAttributes.CallConvWinapi:
                    cdecl = System.Runtime.InteropServices.CallingConvention.Winapi;
                    break;

                case PInvokeAttributes.CallConvCdecl:
                    cdecl = System.Runtime.InteropServices.CallingConvention.Cdecl;
                    break;
            }
            bool exactSpelling = (bestFitUseAssem & PInvokeAttributes.NoMangle) != PInvokeAttributes.BestFitUseAssem;
            bool setLastError = (bestFitUseAssem & PInvokeAttributes.SupportsLastError) != PInvokeAttributes.BestFitUseAssem;
            bool bestFitMapping = (bestFitUseAssem & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (bestFitUseAssem & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            return new DllImportAttribute(importDll, str, none, exactSpelling, setLastError, (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != MethodImplAttributes.IL, cdecl, bestFitMapping, throwOnUnmappableChar);
        }
 internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
 {
     if ((method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) == MethodImplAttributes.IL)
     {
         return null;
     }
     return new PreserveSigAttribute();
 }
Example #4
0
 /// <include file='doc\Delegate.uex' path='docs/doc[@for="Delegate.DynamicInvokeImpl"]/*' />
 protected virtual Object DynamicInvokeImpl(Object[] args)
 {
     if (_method == null) 
         _method = InternalFindMethodInfo();
     // Use internal version of invoke to avoid access check (performed
     // during delegate creation).
     return _method.InternalInvoke(_target,BindingFlags.Default,null,args,null,false);
 }
 internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeMethodInfo target)
 {
     IList<CustomAttributeData> customAttributes = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);
     int count = 0;
     Attribute[] attributeArray = PseudoCustomAttribute.GetCustomAttributes(target, typeof(object) as RuntimeType, true, out count);
     if (count == 0)
     {
         return customAttributes;
     }
     CustomAttributeData[] array = new CustomAttributeData[customAttributes.Count + count];
     customAttributes.CopyTo(array, count);
     for (int i = 0; i < count; i++)
     {
         array[i] = new CustomAttributeData(attributeArray[i]);
     }
     return Array.AsReadOnly<CustomAttributeData>(array);
 }
Example #6
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
        {
            if ((method.Attributes & MethodAttributes.PinvokeImpl) == 0)
                return null;

#if !MONO
            MetadataImport scope = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
#endif
            string entryPoint, dllName = null;
            int token = method.MetadataToken;
            PInvokeAttributes flags = 0;

#if MONO
            ((MonoMethod)method).GetPInvoke(out flags, out entryPoint, out dllName);
#else
            scope.GetPInvokeMap(token, out flags, out entryPoint, out dllName);
#endif

            CharSet charSet = CharSet.None;

            switch (flags & PInvokeAttributes.CharSetMask)
            {
                case PInvokeAttributes.CharSetNotSpec: charSet = CharSet.None; break;
                case PInvokeAttributes.CharSetAnsi: charSet = CharSet.Ansi; break;
                case PInvokeAttributes.CharSetUnicode: charSet = CharSet.Unicode; break;
                case PInvokeAttributes.CharSetAuto: charSet = CharSet.Auto; break;

                // Invalid: default to CharSet.None
                default: break;
            }

            CallingConvention callingConvention = CallingConvention.Cdecl;

            switch (flags & PInvokeAttributes.CallConvMask)
            {
                case PInvokeAttributes.CallConvWinapi: callingConvention = CallingConvention.Winapi; break;
                case PInvokeAttributes.CallConvCdecl: callingConvention = CallingConvention.Cdecl; break;
                case PInvokeAttributes.CallConvStdcall: callingConvention = CallingConvention.StdCall; break;
                case PInvokeAttributes.CallConvThiscall: callingConvention = CallingConvention.ThisCall; break;
                case PInvokeAttributes.CallConvFastcall: callingConvention = CallingConvention.FastCall; break;

                // Invalid: default to CallingConvention.Cdecl
                default: break;
            }

            bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig = (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            return new DllImportAttribute(
                dllName, entryPoint, charSet, exactSpelling, setLastError, preserveSig,
                callingConvention, bestFitMapping, throwOnUnmappableChar);
        }
Example #7
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType)
        {
            bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
            if (!all && s_pca.GetValueOrDefault(caType) == null)
                return false;

            if (all || caType == (RuntimeType)typeof(DllImportAttribute))
            {
                if (DllImportAttribute.IsDefined(method)) return true;
            }
            if (all || caType == (RuntimeType)typeof(PreserveSigAttribute))
            {
                if (PreserveSigAttribute.IsDefined(method)) return true;
            }
            if (all || IsSecurityAttribute(caType))
            {
                int count;

                if (GetCustomAttributes(method, caType, true, out count).Length != 0)
                    return true;
            }

            return false;
        }
Example #8
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
                method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;

            int pcaCount = 0;
            Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out pcaCount);

            // if we are asked to go up the hierarchy chain we have to do it now and regardless of the
            // attribute usage for the specific attribute because a derived attribute may override the usage...           
            // ... however if the attribute is sealed we can rely on the attribute usage
            if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(method));
                if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount);
                return attributes;
            }

            List<object> result = new List<object>();
            bool mustBeInheritable = false;
            bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters);
            Type arrayType = useObjectArray ? typeof(object) : caType;

            while (pcaCount > 0) 
                result.Add(pca[--pcaCount]);
                
            while (method != null)
            {
                object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method));
                mustBeInheritable = true;
                for (int i = 0; i < attributes.Length; i++)
                    result.Add(attributes[i]);

                method = method.GetParentDefinition();
            }

            object[] typedResult = CreateAttributeArrayHelper(arrayType, result.Count);
            Array.Copy(result.ToArray(), 0, typedResult, 0, result.Count);
            return typedResult;
        }
Example #9
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static IList<CustomAttributeData> GetCustomAttributesInternal(RuntimeMethodInfo target)
        {
            Contract.Assert(target != null);

            IList<CustomAttributeData> cad = GetCustomAttributes(target.GetRuntimeModule(), target.MetadataToken);

            int pcaCount = 0;
            Attribute[] a = PseudoCustomAttribute.GetCustomAttributes((RuntimeMethodInfo)target, typeof(object) as RuntimeType, true, out pcaCount);

            if (pcaCount == 0)
                return cad;

            CustomAttributeData[] pca = new CustomAttributeData[cad.Count + pcaCount];
            cad.CopyTo(pca, pcaCount);
            for (int i = 0; i < pcaCount; i++)
            {
                pca[i] = new CustomAttributeData(a[i]);
            }

            return Array.AsReadOnly(pca);
        }
Example #10
0
        internal static void AssignAssociates(MetadataImport scope, int mdPropEvent, RuntimeType declaringType, RuntimeType reflectedType, out RuntimeMethodInfo addOn, out RuntimeMethodInfo removeOn, out RuntimeMethodInfo fireOn, out RuntimeMethodInfo getter, out RuntimeMethodInfo setter, out MethodInfo[] other, out bool composedOfAllPrivateMethods, out BindingFlags bindingFlags)
        {
            addOn = removeOn = fireOn = getter = setter = (RuntimeMethodInfo)null;
            Associates.Attributes attributes1 = Associates.Attributes.ComposedOfAllVirtualMethods | Associates.Attributes.ComposedOfAllPrivateMethods | Associates.Attributes.ComposedOfNoPublicMembers | Associates.Attributes.ComposedOfNoStaticMembers;
            while (RuntimeTypeHandle.IsGenericVariable(reflectedType))
            {
                reflectedType = (RuntimeType)reflectedType.BaseType;
            }
            bool isInherited = declaringType != reflectedType;
            List <MethodInfo>  methodInfoList = (List <MethodInfo>)null;
            MetadataEnumResult result;

            scope.Enum(MetadataTokenType.MethodDef, mdPropEvent, out result);
            int capacity = result.Length / 2;

            for (int index = 0; index < capacity; ++index)
            {
                int tkMethod = result[index * 2];
                MethodSemanticsAttributes semanticsAttributes = (MethodSemanticsAttributes)result[index * 2 + 1];
                RuntimeType       declaredType      = declaringType;
                RuntimeType       reflectedType1    = reflectedType;
                RuntimeMethodInfo runtimeMethodInfo = Associates.AssignAssociates(tkMethod, declaredType, reflectedType1);
                if (!((MethodInfo)runtimeMethodInfo == (MethodInfo)null))
                {
                    MethodAttributes attributes2 = runtimeMethodInfo.Attributes;
                    bool             flag1       = (attributes2 & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                    bool             flag2       = (uint)(attributes2 & MethodAttributes.Virtual) > 0U;
                    int  num   = (attributes2 & MethodAttributes.MemberAccessMask) == MethodAttributes.Public ? 1 : 0;
                    bool flag3 = (uint)(attributes2 & MethodAttributes.Static) > 0U;
                    if (num != 0)
                    {
                        attributes1 = attributes1 & ~Associates.Attributes.ComposedOfNoPublicMembers & ~Associates.Attributes.ComposedOfAllPrivateMethods;
                    }
                    else if (!flag1)
                    {
                        attributes1 &= ~Associates.Attributes.ComposedOfAllPrivateMethods;
                    }
                    if (flag3)
                    {
                        attributes1 &= ~Associates.Attributes.ComposedOfNoStaticMembers;
                    }
                    if (!flag2)
                    {
                        attributes1 &= ~Associates.Attributes.ComposedOfAllVirtualMethods;
                    }
                    if (semanticsAttributes == MethodSemanticsAttributes.Setter)
                    {
                        setter = runtimeMethodInfo;
                    }
                    else if (semanticsAttributes == MethodSemanticsAttributes.Getter)
                    {
                        getter = runtimeMethodInfo;
                    }
                    else if (semanticsAttributes == MethodSemanticsAttributes.Fire)
                    {
                        fireOn = runtimeMethodInfo;
                    }
                    else if (semanticsAttributes == MethodSemanticsAttributes.AddOn)
                    {
                        addOn = runtimeMethodInfo;
                    }
                    else if (semanticsAttributes == MethodSemanticsAttributes.RemoveOn)
                    {
                        removeOn = runtimeMethodInfo;
                    }
                    else
                    {
                        if (methodInfoList == null)
                        {
                            methodInfoList = new List <MethodInfo>(capacity);
                        }
                        methodInfoList.Add((MethodInfo)runtimeMethodInfo);
                    }
                }
            }
            bool isPublic = (attributes1 & Associates.Attributes.ComposedOfNoPublicMembers) == (Associates.Attributes) 0;
            bool isStatic = (attributes1 & Associates.Attributes.ComposedOfNoStaticMembers) == (Associates.Attributes) 0;

            bindingFlags = RuntimeType.FilterPreCalculate(isPublic, isInherited, isStatic);
            composedOfAllPrivateMethods = (uint)(attributes1 & Associates.Attributes.ComposedOfAllPrivateMethods) > 0U;
            other = methodInfoList != null?methodInfoList.ToArray() : (MethodInfo[])null;
        }
Example #11
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static unsafe void AssignAssociates(
            MetadataImport scope,
            int mdPropEvent,
            RuntimeType declaringType,
            RuntimeType reflectedType,
            out RuntimeMethodInfo addOn,
            out RuntimeMethodInfo removeOn,
            out RuntimeMethodInfo fireOn,
            out RuntimeMethodInfo getter,
            out RuntimeMethodInfo setter,
            out MethodInfo[] other,
            out bool composedOfAllPrivateMethods,
            out BindingFlags bindingFlags)
        {
            addOn = removeOn = fireOn = getter = setter = null;

            Attributes attributes =
                Attributes.ComposedOfAllPrivateMethods |
                Attributes.ComposedOfAllVirtualMethods |
                Attributes.ComposedOfNoPublicMembers |
                Attributes.ComposedOfNoStaticMembers;

            while (RuntimeTypeHandle.IsGenericVariable(reflectedType))
            {
                reflectedType = (RuntimeType)reflectedType.BaseType;
            }

            bool isInherited = declaringType != reflectedType;

            List <MethodInfo> otherList = null;

            MetadataEnumResult associatesData;

            scope.Enum(MetadataTokenType.MethodDef, mdPropEvent, out associatesData);

            int cAssociates = associatesData.Length / 2;

            for (int i = 0; i < cAssociates; i++)
            {
                int methodDefToken = associatesData[i * 2];
                MethodSemanticsAttributes semantics = (MethodSemanticsAttributes)associatesData[i * 2 + 1];

                #region Assign each associate
                RuntimeMethodInfo associateMethod =
                    AssignAssociates(methodDefToken, declaringType, reflectedType);

                if (associateMethod == null)
                {
                    continue;
                }

                MethodAttributes methAttr  = associateMethod.Attributes;
                bool             isPrivate = (methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                bool             isVirtual = (methAttr & MethodAttributes.Virtual) != 0;

                MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
                bool             isPublic   = visibility == MethodAttributes.Public;
                bool             isStatic   = (methAttr & MethodAttributes.Static) != 0;

                if (isPublic)
                {
                    attributes &= ~Attributes.ComposedOfNoPublicMembers;
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }
                else if (!isPrivate)
                {
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }

                if (isStatic)
                {
                    attributes &= ~Attributes.ComposedOfNoStaticMembers;
                }

                if (!isVirtual)
                {
                    attributes &= ~Attributes.ComposedOfAllVirtualMethods;
                }
                #endregion

                if (semantics == MethodSemanticsAttributes.Setter)
                {
                    setter = associateMethod;
                }
                else if (semantics == MethodSemanticsAttributes.Getter)
                {
                    getter = associateMethod;
                }
                else if (semantics == MethodSemanticsAttributes.Fire)
                {
                    fireOn = associateMethod;
                }
                else if (semantics == MethodSemanticsAttributes.AddOn)
                {
                    addOn = associateMethod;
                }
                else if (semantics == MethodSemanticsAttributes.RemoveOn)
                {
                    removeOn = associateMethod;
                }
                else
                {
                    if (otherList == null)
                    {
                        otherList = new List <MethodInfo>(cAssociates);
                    }
                    otherList.Add(associateMethod);
                }
            }

            bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
            bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
            bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);

            composedOfAllPrivateMethods = (attributes & Attributes.ComposedOfAllPrivateMethods) != 0;

            other = (otherList != null) ? otherList.ToArray() : null;
        }
Example #12
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public static MethodBase GetCurrentMethod()
        {
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

            return(RuntimeMethodInfo.InternalGetCurrentMethod(ref stackMark));
        }
Example #13
0
        internal static unsafe object[] GetCustomAttributes(Module decoratedModule, int decoratedMetadataToken, int pcaCount, RuntimeType attributeFilterType, bool mustBeInheritable, IList derivedAttributes)
        {
            if (decoratedModule.Assembly.ReflectionOnly)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Arg_ReflectionOnlyCA"));
            }
            MetadataImport metadataImport = decoratedModule.MetadataImport;

            CustomAttributeRecord[] customAttributeRecords = CustomAttributeData.GetCustomAttributeRecords(decoratedModule, decoratedMetadataToken);
            Type elementType = (((attributeFilterType == null) || attributeFilterType.IsValueType) || attributeFilterType.ContainsGenericParameters) ? typeof(object) : attributeFilterType;

            if ((attributeFilterType == null) && (customAttributeRecords.Length == 0))
            {
                return(Array.CreateInstance(elementType, 0) as object[]);
            }
            object[]             attributes = Array.CreateInstance(elementType, customAttributeRecords.Length) as object[];
            int                  length     = 0;
            SecurityContextFrame frame      = new SecurityContextFrame();

            frame.Push(decoratedModule.Assembly.InternalAssembly);
            Assembly lastAptcaOkAssembly = null;

            for (int i = 0; i < customAttributeRecords.Length; i++)
            {
                bool   flag2;
                bool   flag3;
                object obj2 = null;
                CustomAttributeRecord caRecord      = customAttributeRecords[i];
                RuntimeMethodHandle   ctor          = new RuntimeMethodHandle();
                RuntimeType           attributeType = null;
                int    namedArgs = 0;
                IntPtr signature = caRecord.blob.Signature;
                IntPtr blobEnd   = (IntPtr)(((void *)signature) + caRecord.blob.Length);
                if (FilterCustomAttributeRecord(caRecord, metadataImport, ref lastAptcaOkAssembly, decoratedModule, decoratedMetadataToken, attributeFilterType, mustBeInheritable, attributes, derivedAttributes, out attributeType, out ctor, out flag2, out flag3))
                {
                    if (!ctor.IsNullHandle())
                    {
                        ctor.CheckLinktimeDemands(decoratedModule, decoratedMetadataToken);
                    }
                    RuntimeConstructorInfo.CheckCanCreateInstance(attributeType, flag3);
                    if (flag2)
                    {
                        obj2 = CreateCaObject(decoratedModule, ctor, ref signature, blobEnd, out namedArgs);
                    }
                    else
                    {
                        obj2 = attributeType.TypeHandle.CreateCaInstance(ctor);
                        if (Marshal.ReadInt16(signature) != 1)
                        {
                            throw new CustomAttributeFormatException();
                        }
                        signature = (IntPtr)(((void *)signature) + 2);
                        namedArgs = Marshal.ReadInt16(signature);
                        signature = (IntPtr)(((void *)signature) + 2);
                    }
                    for (int j = 0; j < namedArgs; j++)
                    {
                        string str;
                        bool   flag4;
                        Type   type3;
                        object obj3;
                        IntPtr ptr1 = caRecord.blob.Signature;
                        GetPropertyOrFieldData(decoratedModule, ref signature, blobEnd, out str, out flag4, out type3, out obj3);
                        try
                        {
                            if (flag4)
                            {
                                if ((type3 == null) && (obj3 != null))
                                {
                                    type3 = (obj3.GetType() == typeof(RuntimeType)) ? typeof(Type) : obj3.GetType();
                                }
                                RuntimePropertyInfo property = null;
                                if (type3 == null)
                                {
                                    property = attributeType.GetProperty(str) as RuntimePropertyInfo;
                                }
                                else
                                {
                                    property = attributeType.GetProperty(str, type3, Type.EmptyTypes) as RuntimePropertyInfo;
                                }
                                RuntimeMethodInfo setMethod = property.GetSetMethod(true) as RuntimeMethodInfo;
                                if (setMethod.IsPublic)
                                {
                                    setMethod.MethodHandle.CheckLinktimeDemands(decoratedModule, decoratedMetadataToken);
                                    setMethod.Invoke(obj2, BindingFlags.Default, null, new object[] { obj3 }, null, true);
                                }
                            }
                            else
                            {
                                (attributeType.GetField(str) as RtFieldInfo).InternalSetValue(obj2, obj3, BindingFlags.Default, Type.DefaultBinder, null, false);
                            }
                        }
                        catch (Exception exception)
                        {
                            throw new CustomAttributeFormatException(string.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString(flag4 ? "RFLCT.InvalidPropFail" : "RFLCT.InvalidFieldFail"), new object[] { str }), exception);
                        }
                    }
                    if (!signature.Equals(blobEnd))
                    {
                        throw new CustomAttributeFormatException();
                    }
                    attributes[length++] = obj2;
                }
            }
            frame.Pop();
            if ((length == customAttributeRecords.Length) && (pcaCount == 0))
            {
                return(attributes);
            }
            if (length == 0)
            {
                Array.CreateInstance(elementType, 0);
            }
            object[] destinationArray = Array.CreateInstance(elementType, (int)(length + pcaCount)) as object[];
            Array.Copy(attributes, 0, destinationArray, 0, length);
            return(destinationArray);
        }
Example #14
0
 internal static extern int get_metadata_token(RuntimeMethodInfo method);
Example #15
0
 internal static extern RuntimeMethodInfo get_base_method(RuntimeMethodInfo method, bool definition);
Example #16
0
 internal static ParameterInfo GetReturnParameterInfo(RuntimeMethodInfo method)
 {
     return(RuntimeParameterInfo.New(GetReturnType(method.mhandle), method, get_retval_marshal(method.mhandle)));
 }
Example #17
0
 public override MethodBody GetMethodBody()
 {
     return(RuntimeMethodInfo.GetMethodBody(mhandle));
 }
Example #18
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static unsafe void AssignAssociates(
            MetadataImport scope,
            int mdPropEvent,
            RuntimeType declaringType,
            RuntimeType reflectedType,
            out RuntimeMethodInfo addOn,
            out RuntimeMethodInfo removeOn,
            out RuntimeMethodInfo fireOn,
            out RuntimeMethodInfo getter,
            out RuntimeMethodInfo setter,
            out MethodInfo[] other,
            out bool composedOfAllPrivateMethods,
            out BindingFlags bindingFlags)
        {
            addOn = removeOn = fireOn = getter = setter = null;

            Attributes attributes = 
                Attributes.ComposedOfAllPrivateMethods |
                Attributes.ComposedOfAllVirtualMethods |
                Attributes.ComposedOfNoPublicMembers |
                Attributes.ComposedOfNoStaticMembers;

            while(RuntimeTypeHandle.IsGenericVariable(reflectedType))
                reflectedType = (RuntimeType)reflectedType.BaseType;

            bool isInherited = declaringType != reflectedType;

            List<MethodInfo> otherList = null;

            MetadataEnumResult associatesData;
            scope.Enum(MetadataTokenType.MethodDef, mdPropEvent, out associatesData);

            int cAssociates = associatesData.Length / 2;

            for (int i = 0; i < cAssociates; i++)
            {
                int methodDefToken = associatesData[i * 2];
                MethodSemanticsAttributes semantics = (MethodSemanticsAttributes)associatesData[i * 2 + 1];

                #region Assign each associate
                RuntimeMethodInfo associateMethod =
                    AssignAssociates(methodDefToken, declaringType, reflectedType);

                if (associateMethod == null)
                    continue;

                MethodAttributes methAttr = associateMethod.Attributes;
                bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;

                MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask;
                bool isPublic = visibility == MethodAttributes.Public;
                bool isStatic =(methAttr & MethodAttributes.Static) != 0;

                if (isPublic)
                {
                    attributes &= ~Attributes.ComposedOfNoPublicMembers;
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }
                else if (!isPrivate)
                {
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }

                if (isStatic)
                    attributes &= ~Attributes.ComposedOfNoStaticMembers;

                if (!isVirtual)
                    attributes &= ~Attributes.ComposedOfAllVirtualMethods;
                #endregion

                if (semantics == MethodSemanticsAttributes.Setter)
                    setter = associateMethod;
                else if (semantics == MethodSemanticsAttributes.Getter)
                    getter = associateMethod;
                else if (semantics == MethodSemanticsAttributes.Fire)
                    fireOn = associateMethod;
                else if (semantics == MethodSemanticsAttributes.AddOn)
                    addOn = associateMethod;
                else if (semantics == MethodSemanticsAttributes.RemoveOn)
                    removeOn = associateMethod;
                else
                {
                    if (otherList == null)
                        otherList = new List<MethodInfo>(cAssociates);
                    otherList.Add(associateMethod);
                }
            }

            bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
            bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
            bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);

            composedOfAllPrivateMethods =(attributes & Attributes.ComposedOfAllPrivateMethods) != 0;

            other = (otherList != null) ? otherList.ToArray() : null;
        }
Example #19
0
        internal static Delegate CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags, ref StackCrawlMark stackMark)
        {
            Contract.Assert((flags & DelegateBindingFlags.SkipSecurityChecks) == 0);

#if FEATURE_APPX
            bool nonW8PMethod = (rtMethod.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
            bool nonW8PType = (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0;
            if (nonW8PMethod || nonW8PType)
            {
                RuntimeAssembly caller = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                if (caller != null && !caller.IsSafeForReflection())
                    throw new InvalidOperationException(
                        Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext",
                                                      nonW8PMethod ? rtMethod.FullName : rtType.FullName));
            }
#endif

            return UnsafeCreateDelegate(rtType, rtMethod, firstArgument, flags);
        }
Example #20
0
 internal static unsafe void AssignAssociates(AssociateRecord* associates, int cAssociates, RuntimeTypeHandle declaringTypeHandle, RuntimeTypeHandle reflectedTypeHandle, out RuntimeMethodInfo addOn, out RuntimeMethodInfo removeOn, out RuntimeMethodInfo fireOn, out RuntimeMethodInfo getter, out RuntimeMethodInfo setter, out MethodInfo[] other, out bool composedOfAllPrivateMethods, out BindingFlags bindingFlags)
 {
     RuntimeMethodInfo info2;
     RuntimeMethodInfo info3;
     RuntimeMethodInfo info4;
     setter = (RuntimeMethodInfo) (info2 = null);
     getter = info3 = info2;
     fireOn = info4 = info3;
     addOn = removeOn = info4;
     other = null;
     Attributes attributes = Attributes.ComposedOfNoStaticMembers | Attributes.ComposedOfNoPublicMembers | Attributes.ComposedOfAllPrivateMethods | Attributes.ComposedOfAllVirtualMethods;
     while (reflectedTypeHandle.IsGenericVariable())
     {
         reflectedTypeHandle = reflectedTypeHandle.GetRuntimeType().BaseType.GetTypeHandleInternal();
     }
     bool isInherited = !declaringTypeHandle.Equals(reflectedTypeHandle);
     ArrayList list = new ArrayList();
     for (int i = 0; i < cAssociates; i++)
     {
         RuntimeMethodInfo info = AssignAssociates(associates[i].MethodDefToken, declaringTypeHandle, reflectedTypeHandle);
         if (info != null)
         {
             MethodAttributes attributes2 = info.Attributes;
             bool flag2 = (attributes2 & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
             bool flag3 = (attributes2 & MethodAttributes.Virtual) != MethodAttributes.PrivateScope;
             MethodAttributes attributes3 = attributes2 & MethodAttributes.MemberAccessMask;
             bool flag4 = attributes3 == MethodAttributes.Public;
             bool flag5 = (attributes2 & MethodAttributes.Static) != MethodAttributes.PrivateScope;
             if (flag4)
             {
                 attributes &= ~Attributes.ComposedOfNoPublicMembers;
                 attributes &= ~Attributes.ComposedOfAllPrivateMethods;
             }
             else if (!flag2)
             {
                 attributes &= ~Attributes.ComposedOfAllPrivateMethods;
             }
             if (flag5)
             {
                 attributes &= ~Attributes.ComposedOfNoStaticMembers;
             }
             if (!flag3)
             {
                 attributes &= ~Attributes.ComposedOfAllVirtualMethods;
             }
             if (associates[i].Semantics == MethodSemanticsAttributes.Setter)
             {
                 setter = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.Getter)
             {
                 getter = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.Fire)
             {
                 fireOn = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.AddOn)
             {
                 addOn = info;
             }
             else if (associates[i].Semantics == MethodSemanticsAttributes.RemoveOn)
             {
                 removeOn = info;
             }
             else
             {
                 list.Add(info);
             }
         }
     }
     bool isPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
     bool isStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0;
     bindingFlags = RuntimeType.FilterPreCalculate(isPublic, isInherited, isStatic);
     composedOfAllPrivateMethods = (attributes & Attributes.ComposedOfAllPrivateMethods) != 0;
     other = (MethodInfo[]) list.ToArray(typeof(MethodInfo));
 }
        private int GetTokenFor(RuntimeMethodInfo rtMeth, RuntimeType rtType)
        {
#if FEATURE_APPX
            if (ProfileAPICheck)
            {
                if ((rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));

                if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
            }
#endif

            return m_scope.GetTokenFor(rtMeth.MethodHandle, rtType.TypeHandle);
        }
Example #22
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.

                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);
        }
 internal VarArgMethod(RuntimeMethodInfo method, SignatureHelper signature)
 {
     m_method = method;
     m_signature = signature;
 }
 internal static bool IsDefined(RuntimeMethodInfo method)
 {
     return ((method.Attributes & MethodAttributes.PinvokeImpl) != MethodAttributes.PrivateScope);
 }
        private int GetTokenForVarArgMethod(RuntimeMethodInfo rtMeth, SignatureHelper sig)
        {
#if FEATURE_APPX
            if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
#endif
            VarArgMethod varArgMeth = new VarArgMethod(rtMeth, sig);
            return m_scope.GetTokenFor(varArgMeth);
        }
 internal RemotingMethodCachedData(RuntimeMethodInfo ri) : base(ri)
 {
 }
Example #27
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            if (PseudoCustomAttribute.IsDefined(method, caType))
                return true;

            if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
                return true;

            if (!inherit)
                return false;

            method = method.GetParentDefinition();

            while (method != null)
            {
                if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
                    return true;

                method = method.GetParentDefinition();
            }

            return false;
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.DynamicTypeUsage) && caType != null)
            {
                FrameworkEventSource.Log.QueryAttributeIsDefined(caType.GetFullNameForEtw());
            }
#endif

            if (PseudoCustomAttribute.IsDefined(method, caType))
                return true;

            if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType))
                return true;

            if (!inherit)
                return false;

            method = method.GetParentDefinition();

            while (method != null)
            {
                if (IsCustomAttributeDefined(method.GetRuntimeModule(), method.MetadataToken, caType, 0, inherit))
                    return true;

                method = method.GetParentDefinition();
            }

            return false;
        }
Example #29
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Attribute[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool includeSecCa, out int count)
        {
            Contract.Requires(method != null);
            Contract.Requires(caType != null);

            count = 0;

            bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);
            if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType))
                return new Attribute[0];

            List<Attribute> pcas = new List<Attribute>();
            Attribute pca = null;

            if (all || caType == (RuntimeType)typeof(DllImportAttribute))
            {
                pca = DllImportAttribute.GetCustomAttribute(method);
                if (pca != null) pcas.Add(pca);
            }
            if (all || caType == (RuntimeType)typeof(PreserveSigAttribute))
            {
                pca = PreserveSigAttribute.GetCustomAttribute(method);
                if (pca != null) pcas.Add(pca);
            }
            if (includeSecCa && (all || IsSecurityAttribute(caType)))
            {
                object[] securityAttributes;

                GetSecurityAttributes(method.Module.ModuleHandle.GetRuntimeModule(), method.MetadataToken, false, out securityAttributes);
                if (securityAttributes != null)
                    foreach (object a in securityAttributes)
                        if (caType == a.GetType() || a.GetType().IsSubclassOf(caType))
                            pcas.Add((Attribute)a);
            }

            count = pcas.Count;
            return pcas.ToArray();
        }
        private int[] _marshalResponseMap = null; // map of parameters that should be marshaled out

        internal RemotingMethodCachedData(RuntimeMethodInfo ri)
        {
            RI = ri;
        }
Example #31
0
 internal static bool IsDefined(RuntimeMethodInfo method)
 {
     return (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
 }
Example #32
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static unsafe void AssignAssociates( 
            AssociateRecord* associates, 
            int cAssociates,
            RuntimeType declaringType, 
            RuntimeType reflectedType,
            out RuntimeMethodInfo addOn,
            out RuntimeMethodInfo removeOn,
            out RuntimeMethodInfo fireOn, 
            out RuntimeMethodInfo getter,
            out RuntimeMethodInfo setter, 
            out MethodInfo[] other, 
            out bool composedOfAllPrivateMethods,
            out BindingFlags bindingFlags) 
        {
            addOn = removeOn = fireOn = getter = setter = null;
            other = null;
 
            Attributes attributes =
                Attributes.ComposedOfAllPrivateMethods | 
                Attributes.ComposedOfAllVirtualMethods | 
                Attributes.ComposedOfNoPublicMembers |
                Attributes.ComposedOfNoStaticMembers; 

            while(RuntimeTypeHandle.IsGenericVariable(reflectedType))
                reflectedType = (RuntimeType)reflectedType.BaseType;
 
            bool isInherited = declaringType != reflectedType;
 
            List<MethodInfo> otherList = new List<MethodInfo>(cAssociates); 

            for (int i = 0; i < cAssociates; i++) 
            {
                #region Assign each associate
                RuntimeMethodInfo associateMethod =
                    AssignAssociates(associates[i].MethodDefToken, declaringType, reflectedType); 

                if (associateMethod == null) 
                    continue; 

                MethodAttributes methAttr = associateMethod.Attributes; 
                bool isPrivate =(methAttr & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                bool isVirtual =(methAttr & MethodAttributes.Virtual) != 0;

                MethodAttributes visibility = methAttr & MethodAttributes.MemberAccessMask; 
                bool isPublic = visibility == MethodAttributes.Public;
                bool isStatic =(methAttr & MethodAttributes.Static) != 0; 
 
                if (isPublic)
                { 
                    attributes &= ~Attributes.ComposedOfNoPublicMembers;
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods;
                }
                else if (!isPrivate) 
                {
                    attributes &= ~Attributes.ComposedOfAllPrivateMethods; 
                } 

                if (isStatic) 
                    attributes &= ~Attributes.ComposedOfNoStaticMembers;

                if (!isVirtual)
                    attributes &= ~Attributes.ComposedOfAllVirtualMethods; 
                #endregion
 
                if (associates[i].Semantics == MethodSemanticsAttributes.Setter) 
                    setter = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.Getter) 
                    getter = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.Fire)
                    fireOn = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.AddOn) 
                    addOn = associateMethod;
                else if (associates[i].Semantics == MethodSemanticsAttributes.RemoveOn) 
                    removeOn = associateMethod; 
                else
                    otherList.Add(associateMethod); 
            }

            bool isPseudoPublic = (attributes & Attributes.ComposedOfNoPublicMembers) == 0;
            bool isPseudoStatic = (attributes & Attributes.ComposedOfNoStaticMembers) == 0; 
            bindingFlags = RuntimeType.FilterPreCalculate(isPseudoPublic, isInherited, isPseudoStatic);
 
            composedOfAllPrivateMethods =(attributes & Attributes.ComposedOfAllPrivateMethods) != 0; 

            other = otherList.ToArray(); 
        }
Example #33
0
 internal static bool IsDefined(RuntimeMethodInfo method)
 {
     return (method.Attributes & MethodAttributes.PinvokeImpl) != 0;
 }
Example #34
0
 internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
     {
         method = method.GetGenericMethodDefinition() as RuntimeMethodInfo;
     }
     int count = 0;
     Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count);
     if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
     {
         object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType);
         if (count > 0)
         {
             Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
         }
         return objArray;
     }
     List<object> derivedAttributes = new List<object>();
     bool mustBeInheritable = false;
     Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;
     while (count > 0)
     {
         derivedAttributes.Add(sourceArray[--count]);
     }
     while (method != null)
     {
         object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes);
         mustBeInheritable = true;
         for (int i = 0; i < objArray2.Length; i++)
         {
             derivedAttributes.Add(objArray2[i]);
         }
         method = method.GetParentDefinition() as RuntimeMethodInfo;
     }
     object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[];
     Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
     return destinationArray;
 }
Example #35
0
		internal RuntimeMethodInfo[] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, RuntimeType reflectedType)
		{
			var refh = new RuntimeTypeHandle (reflectedType);
			using (var h = new Mono.SafeGPtrArrayHandle (GetMethodsByName_native (name, bindingAttr, ignoreCase))) {
				var n = h.Length;
				var a = new RuntimeMethodInfo [n];
				for (int i = 0; i < n; i++) {
					var mh = new RuntimeMethodHandle (h[i]);
					a[i] = (RuntimeMethodInfo) MethodBase.GetMethodFromHandleNoGenericCheck (mh, refh);
				}
				return a;
			}
		}
Example #36
0
 internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType, bool inherit)
 {
     if (PseudoCustomAttribute.IsDefined(method, caType))
     {
         return true;
     }
     if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType))
     {
         return true;
     }
     if (inherit)
     {
         method = method.GetParentDefinition() as RuntimeMethodInfo;
         while (method != null)
         {
             if (IsCustomAttributeDefined(method.Module, method.MetadataToken, caType, inherit))
             {
                 return true;
             }
             method = method.GetParentDefinition() as RuntimeMethodInfo;
         }
     }
     return false;
 }
Example #37
0
        [System.Security.SecurityCritical]  // auto-generated
        private int GetMemberRefOfMethodInfo(int tr, RuntimeMethodInfo method)
        {
            Contract.Assert(method != null);

#if FEATURE_APPX
            if (ContainingAssemblyBuilder.ProfileAPICheck)
            {
                if ((method.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", method.FullName));
            }
#endif

            return GetMemberRefOfMethodInfo(GetNativeHandle(), tr, method);
        }
Example #38
0
        internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags)
        {
            Delegate d = InternalAlloc(rtType);

            if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags))
                return d;
            else
                return null;
        }
Example #39
0
        internal static Delegate UnsafeCreateDelegate(RuntimeType rtType, RuntimeMethodInfo rtMethod, Object firstArgument, DelegateBindingFlags flags)
        {

#if FEATURE_LEGACYNETCF
            if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                if(rtMethod.IsGenericMethodDefinition)
                    throw new MissingMethodException(rtMethod.DeclaringType.FullName, rtMethod.Name);
#endif

            Delegate d = InternalAlloc(rtType);

            if (d.BindToMethodInfo(firstArgument, rtMethod, rtMethod.GetDeclaringTypeInternal(), flags))
                return d;
            else
                return null;
        }
 internal static IList <CustomAttributeData> GetCustomAttributesInternal(RuntimeMethodInfo target)
 {
     return(CustomAttribute.GetCustomAttributesData(target));
 }