Beispiel #1
0
        private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type type, bool inherit)
        {
            Attribute[] attributes = (Attribute[])element.GetCustomAttributes(type, inherit);
            if (!inherit)
            {
                return(attributes);
            }
            Dictionary <Type, AttributeUsageAttribute> types = new Dictionary <Type, AttributeUsageAttribute>(11);
            List <Attribute> attributeList = new List <Attribute>();

            Attribute.CopyToArrayList(attributeList, attributes, types);
            for (EventInfo parentDefinition = Attribute.GetParentDefinition(element); parentDefinition != (EventInfo)null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
            {
                Attribute[] customAttributes = Attribute.GetCustomAttributes((MemberInfo)parentDefinition, type, false);
                Attribute.AddAttributesToList(attributeList, customAttributes, types);
            }
            Array destinationArray = (Array)Attribute.CreateAttributeArrayHelper(type, attributeList.Count);

            Array.Copy((Array)attributeList.ToArray(), 0, destinationArray, 0, attributeList.Count);
            return((Attribute[])destinationArray);
        }
Beispiel #2
0
        private static Attribute[] InternalParamGetCustomAttributes(ParameterInfo param, Type type, bool inherit)
        {
            List <Type> list = new List <Type>();

            if (type == (Type)null)
            {
                type = typeof(Attribute);
            }
            object[] customAttributes1 = param.GetCustomAttributes(type, false);
            for (int index = 0; index < customAttributes1.Length; ++index)
            {
                Type type1 = customAttributes1[index].GetType();
                if (!Attribute.InternalGetAttributeUsage(type1).AllowMultiple)
                {
                    list.Add(type1);
                }
            }
            Attribute[] attributeArray1 = customAttributes1.Length != 0 ? (Attribute[])customAttributes1 : Attribute.CreateAttributeArrayHelper(type, 0);
            if (param.Member.DeclaringType == (Type)null || !inherit)
            {
                return(attributeArray1);
            }
            for (ParameterInfo parentDefinition = Attribute.GetParentDefinition(param); parentDefinition != null; parentDefinition = Attribute.GetParentDefinition(parentDefinition))
            {
                object[] customAttributes2 = parentDefinition.GetCustomAttributes(type, false);
                int      elementCount      = 0;
                for (int index = 0; index < customAttributes2.Length; ++index)
                {
                    Type type1 = customAttributes2[index].GetType();
                    AttributeUsageAttribute attributeUsage = Attribute.InternalGetAttributeUsage(type1);
                    if (attributeUsage.Inherited && !list.Contains(type1))
                    {
                        if (!attributeUsage.AllowMultiple)
                        {
                            list.Add(type1);
                        }
                        ++elementCount;
                    }
                    else
                    {
                        customAttributes2[index] = (object)null;
                    }
                }
                Attribute[] attributeArrayHelper = Attribute.CreateAttributeArrayHelper(type, elementCount);
                int         index1 = 0;
                for (int index2 = 0; index2 < customAttributes2.Length; ++index2)
                {
                    if (customAttributes2[index2] != null)
                    {
                        attributeArrayHelper[index1] = (Attribute)customAttributes2[index2];
                        ++index1;
                    }
                }
                Attribute[] attributeArray2 = attributeArray1;
                attributeArray1 = Attribute.CreateAttributeArrayHelper(type, attributeArray2.Length + index1);
                Array.Copy((Array)attributeArray2, (Array)attributeArray1, attributeArray2.Length);
                int length = attributeArray2.Length;
                for (int index2 = 0; index2 < attributeArrayHelper.Length; ++index2)
                {
                    attributeArray1[length + index2] = attributeArrayHelper[index2];
                }
            }
            return(attributeArray1);
        }