Exemplo n.º 1
0
        // FilterAttribute
        //  This method will search for a member based upon the attribute passed in.
        //  filterCriteria -- an Int32 representing the attribute
        private static bool FilterAttributeImpl(MemberInfo m, object filterCriteria)
        {
            // Check that the criteria object is an Integer object
            if (filterCriteria == null)
            {
                throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
            }

            switch (m.MemberType)
            {
            case MemberTypes.Constructor:
            case MemberTypes.Method:
            {
                MethodAttributes criteria = 0;
                try
                {
                    int i = (int)filterCriteria;
                    criteria = (MethodAttributes)i;
                }
                catch
                {
                    throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
                }


                MethodAttributes attr;
                if (m.MemberType == MemberTypes.Method)
                {
                    attr = ((MethodInfo)m).Attributes;
                }
                else
                {
                    attr = ((ConstructorInfo)m).Attributes;
                }

                if (((criteria & MethodAttributes.MemberAccessMask) != 0) && (attr & MethodAttributes.MemberAccessMask) != (criteria & MethodAttributes.MemberAccessMask))
                {
                    return(false);
                }
                if (((criteria & MethodAttributes.Static) != 0) && (attr & MethodAttributes.Static) == 0)
                {
                    return(false);
                }
                if (((criteria & MethodAttributes.Final) != 0) && (attr & MethodAttributes.Final) == 0)
                {
                    return(false);
                }
                if (((criteria & MethodAttributes.Virtual) != 0) && (attr & MethodAttributes.Virtual) == 0)
                {
                    return(false);
                }
                if (((criteria & MethodAttributes.Abstract) != 0) && (attr & MethodAttributes.Abstract) == 0)
                {
                    return(false);
                }
                if (((criteria & MethodAttributes.SpecialName) != 0) && (attr & MethodAttributes.SpecialName) == 0)
                {
                    return(false);
                }
                return(true);
            }

            case MemberTypes.Field:
            {
                FieldAttributes criteria = 0;
                try
                {
                    int i = (int)filterCriteria;
                    criteria = (FieldAttributes)i;
                }
                catch
                {
                    throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritInt);
                }

                FieldAttributes attr = ((FieldInfo)m).Attributes;
                if (((criteria & FieldAttributes.FieldAccessMask) != 0) && (attr & FieldAttributes.FieldAccessMask) != (criteria & FieldAttributes.FieldAccessMask))
                {
                    return(false);
                }
                if (((criteria & FieldAttributes.Static) != 0) && (attr & FieldAttributes.Static) == 0)
                {
                    return(false);
                }
                if (((criteria & FieldAttributes.InitOnly) != 0) && (attr & FieldAttributes.InitOnly) == 0)
                {
                    return(false);
                }
                if (((criteria & FieldAttributes.Literal) != 0) && (attr & FieldAttributes.Literal) == 0)
                {
                    return(false);
                }
                if (((criteria & FieldAttributes.NotSerialized) != 0) && (attr & FieldAttributes.NotSerialized) == 0)
                {
                    return(false);
                }
                if (((criteria & FieldAttributes.PinvokeImpl) != 0) && (attr & FieldAttributes.PinvokeImpl) == 0)
                {
                    return(false);
                }
                return(true);
            }
            }

            return(false);
        }
Exemplo n.º 2
0
 public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => HasSameMetadataDefinitionAsCore <RuntimeType> (other);
Exemplo n.º 3
0
        public virtual MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, object filterCriteria)
        {
            // Define the work arrays
            MethodInfo[]      m = null;
            ConstructorInfo[] c = null;
            FieldInfo[]       f = null;
            PropertyInfo[]    p = null;
            EventInfo[]       e = null;
            Type[]            t = null;

            int i   = 0;
            int cnt = 0;            // Total Matchs

            // Check the methods
            if ((memberType & MemberTypes.Method) != 0)
            {
                m = GetMethods(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < m.Length; i++)
                    {
                        if (!filter(m[i], filterCriteria))
                        {
                            m[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += m.Length;
                }
            }

            // Check the constructors
            if ((memberType & MemberTypes.Constructor) != 0)
            {
                c = GetConstructors(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < c.Length; i++)
                    {
                        if (!filter(c[i], filterCriteria))
                        {
                            c[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += c.Length;
                }
            }

            // Check the fields
            if ((memberType & MemberTypes.Field) != 0)
            {
                f = GetFields(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < f.Length; i++)
                    {
                        if (!filter(f[i], filterCriteria))
                        {
                            f[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += f.Length;
                }
            }

            // Check the Properties
            if ((memberType & MemberTypes.Property) != 0)
            {
                p = GetProperties(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < p.Length; i++)
                    {
                        if (!filter(p[i], filterCriteria))
                        {
                            p[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += p.Length;
                }
            }

            // Check the Events
            if ((memberType & MemberTypes.Event) != 0)
            {
                e = GetEvents(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < e.Length; i++)
                    {
                        if (!filter(e[i], filterCriteria))
                        {
                            e[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += e.Length;
                }
            }

            // Check the Types
            if ((memberType & MemberTypes.NestedType) != 0)
            {
                t = GetNestedTypes(bindingAttr);
                if (filter != null)
                {
                    for (i = 0; i < t.Length; i++)
                    {
                        if (!filter(t[i], filterCriteria))
                        {
                            t[i] = null;
                        }
                        else
                        {
                            cnt++;
                        }
                    }
                }
                else
                {
                    cnt += t.Length;
                }
            }

            // Allocate the Member Info
            MemberInfo[] ret = new MemberInfo[cnt];

            // Copy the Methods
            cnt = 0;
            if (m != null)
            {
                for (i = 0; i < m.Length; i++)
                {
                    if (m[i] != null)
                    {
                        ret[cnt++] = m[i];
                    }
                }
            }

            // Copy the Constructors
            if (c != null)
            {
                for (i = 0; i < c.Length; i++)
                {
                    if (c[i] != null)
                    {
                        ret[cnt++] = c[i];
                    }
                }
            }

            // Copy the Fields
            if (f != null)
            {
                for (i = 0; i < f.Length; i++)
                {
                    if (f[i] != null)
                    {
                        ret[cnt++] = f[i];
                    }
                }
            }

            // Copy the Properties
            if (p != null)
            {
                for (i = 0; i < p.Length; i++)
                {
                    if (p[i] != null)
                    {
                        ret[cnt++] = p[i];
                    }
                }
            }

            // Copy the Events
            if (e != null)
            {
                for (i = 0; i < e.Length; i++)
                {
                    if (e[i] != null)
                    {
                        ret[cnt++] = e[i];
                    }
                }
            }

            // Copy the Types
            if (t != null)
            {
                for (i = 0; i < t.Length; i++)
                {
                    if (t[i] != null)
                    {
                        ret[cnt++] = t[i];
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 4
0
 public static bool IsDefined(MemberInfo element, Type attributeType)
 {
     return(IsDefined(element, attributeType, true));
 }
Exemplo n.º 5
0
 public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType)
 {
     return(GetCustomAttribute(element, attributeType, true));
 }
Exemplo n.º 6
0
 private object GetValue(MemberInfo memberInfo)
     => memberInfo switch
     {
Exemplo n.º 7
0
 public static Attribute[] GetCustomAttributes(MemberInfo element)
 {
     return(GetCustomAttributes(element, true));
 }
Exemplo n.º 8
0
 public static Attribute[] GetCustomAttributes(MemberInfo element, Type attributeType, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes((ICustomAttributeProvider)element, attributeType, inherit);
Exemplo n.º 9
0
 public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit) => CustomAttribute.IsDefined((ICustomAttributeProvider)element, attributeType, inherit);
Exemplo n.º 10
0
 public static Attribute[] GetCustomAttributes(MemberInfo element, Type attributeType) => (Attribute[])CustomAttribute.GetCustomAttributes((ICustomAttributeProvider)element, attributeType, true);
Exemplo n.º 11
0
 public static Attribute[] GetCustomAttributes(MemberInfo element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes(element, inherit);
Exemplo n.º 12
0
 public static Attribute[] GetCustomAttributes(MemberInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes(element, true);
Exemplo n.º 13
0
 public static Attribute?GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit) => GetAttr(element, attributeType, inherit);
Exemplo n.º 14
0
 public static Attribute?GetCustomAttribute(MemberInfo element, Type attributeType) => GetAttr(element, attributeType, true);