示例#1
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 = 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;

            scope.Enum(MetadataTokenType.MethodDef, mdPropEvent, out MetadataEnumResult 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
                {
                    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?.ToArray();
        }
        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)
        {
            RuntimeMethodInfo runtimeMethodInfo;

            setter   = (runtimeMethodInfo = null);
            getter   = (runtimeMethodInfo = runtimeMethodInfo);
            fireOn   = (runtimeMethodInfo = runtimeMethodInfo);
            removeOn = (runtimeMethodInfo = runtimeMethodInfo);
            addOn    = runtimeMethodInfo;
            Associates.Attributes attributes = 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>  list = null;
            MetadataEnumResult metadataEnumResult;

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

            for (int i = 0; i < num; i++)
            {
                int tkMethod = metadataEnumResult[i * 2];
                MethodSemanticsAttributes methodSemanticsAttributes = (MethodSemanticsAttributes)metadataEnumResult[i * 2 + 1];
                RuntimeMethodInfo         runtimeMethodInfo2        = Associates.AssignAssociates(tkMethod, declaringType, reflectedType);
                if (!(runtimeMethodInfo2 == null))
                {
                    MethodAttributes attributes2      = runtimeMethodInfo2.Attributes;
                    bool             flag             = (attributes2 & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
                    bool             flag2            = (attributes2 & MethodAttributes.Virtual) > MethodAttributes.PrivateScope;
                    MethodAttributes methodAttributes = attributes2 & MethodAttributes.MemberAccessMask;
                    bool             flag3            = methodAttributes == MethodAttributes.Public;
                    bool             flag4            = (attributes2 & MethodAttributes.Static) > MethodAttributes.PrivateScope;
                    if (flag3)
                    {
                        attributes &= ~Associates.Attributes.ComposedOfNoPublicMembers;
                        attributes &= ~Associates.Attributes.ComposedOfAllPrivateMethods;
                    }
                    else if (!flag)
                    {
                        attributes &= ~Associates.Attributes.ComposedOfAllPrivateMethods;
                    }
                    if (flag4)
                    {
                        attributes &= ~Associates.Attributes.ComposedOfNoStaticMembers;
                    }
                    if (!flag2)
                    {
                        attributes &= ~Associates.Attributes.ComposedOfAllVirtualMethods;
                    }
                    if (methodSemanticsAttributes == MethodSemanticsAttributes.Setter)
                    {
                        setter = runtimeMethodInfo2;
                    }
                    else if (methodSemanticsAttributes == MethodSemanticsAttributes.Getter)
                    {
                        getter = runtimeMethodInfo2;
                    }
                    else if (methodSemanticsAttributes == MethodSemanticsAttributes.Fire)
                    {
                        fireOn = runtimeMethodInfo2;
                    }
                    else if (methodSemanticsAttributes == MethodSemanticsAttributes.AddOn)
                    {
                        addOn = runtimeMethodInfo2;
                    }
                    else if (methodSemanticsAttributes == MethodSemanticsAttributes.RemoveOn)
                    {
                        removeOn = runtimeMethodInfo2;
                    }
                    else
                    {
                        if (list == null)
                        {
                            list = new List <MethodInfo>(num);
                        }
                        list.Add(runtimeMethodInfo2);
                    }
                }
            }
            bool isPublic = (attributes & Associates.Attributes.ComposedOfNoPublicMembers) == (Associates.Attributes) 0;
            bool isStatic = (attributes & Associates.Attributes.ComposedOfNoStaticMembers) == (Associates.Attributes) 0;

            bindingFlags = RuntimeType.FilterPreCalculate(isPublic, isInherited, isStatic);
            composedOfAllPrivateMethods = ((attributes & Associates.Attributes.ComposedOfAllPrivateMethods) > (Associates.Attributes) 0);
            other = ((list != null) ? list.ToArray() : null);
        }
示例#3
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));
        }
示例#4
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;
        }