GetCustomAttributes() public static method

public static GetCustomAttributes ( Assembly target ) : IList
target Assembly
return IList
Esempio n. 1
0
 public override IList <CustomAttributeData> GetCustomAttributesData()
 {
     return(CustomAttributeData.GetCustomAttributes(this));
 }
Esempio n. 2
0
        // returns DBNull.Value if the parameter doesn't have a default value
        private object?GetDefaultValueInternal(bool raw)
        {
            Debug.Assert(!m_noMetadata);

            if (m_noDefaultValue)
            {
                return(DBNull.Value);
            }

            object?defaultValue = null;

            // Why check the parameter type only for DateTime and only for the ctor arguments?
            // No check on the parameter type is done for named args and for Decimal.

            // We should move this after MdToken.IsNullToken(m_tkParamDef) and combine it
            // with the other custom attribute logic. But will that be a breaking change?
            // For a DateTime parameter on which both an md constant and a ca constant are set,
            // which one should win?
            if (ParameterType == typeof(DateTime))
            {
                if (raw)
                {
                    CustomAttributeTypedArgument value =
                        CustomAttributeData.Filter(
                            CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0);

                    if (value.ArgumentType != null)
                    {
                        return(new DateTime((long)value.Value !));
                    }
                }
                else
                {
                    object[] dt = GetCustomAttributes(typeof(DateTimeConstantAttribute), false);
                    if (dt != null && dt.Length != 0)
                    {
                        return(((DateTimeConstantAttribute)dt[0]).Value);
                    }
                }
            }

            #region Look for a default value in metadata
            if (!MdToken.IsNullToken(m_tkParamDef))
            {
                // This will return DBNull.Value if no constant value is defined on m_tkParamDef in the metadata.
                defaultValue = MdConstant.GetValue(m_scope, m_tkParamDef, ParameterType.GetTypeHandleInternal(), raw);
            }
            #endregion

            if (defaultValue == DBNull.Value)
            {
                #region Look for a default value in the custom attributes
                if (raw)
                {
                    foreach (CustomAttributeData attr in CustomAttributeData.GetCustomAttributes(this))
                    {
                        Type?attrType = attr.Constructor.DeclaringType;

                        if (attrType == typeof(DateTimeConstantAttribute))
                        {
                            defaultValue = GetRawDateTimeConstant(attr);
                        }
                        else if (attrType == typeof(DecimalConstantAttribute))
                        {
                            defaultValue = GetRawDecimalConstant(attr);
                        }
                        else if (attrType !.IsSubclassOf(s_CustomConstantAttributeType))
                        {
                            defaultValue = GetRawConstant(attr);
                        }
                    }
                }
                else
                {
                    object[] CustomAttrs = GetCustomAttributes(s_CustomConstantAttributeType, false);
                    if (CustomAttrs.Length != 0)
                    {
                        defaultValue = ((CustomConstantAttribute)CustomAttrs[0]).Value;
                    }
                    else
                    {
                        CustomAttrs = GetCustomAttributes(s_DecimalConstantAttributeType, false);
                        if (CustomAttrs.Length != 0)
                        {
                            defaultValue = ((DecimalConstantAttribute)CustomAttrs[0]).Value;
                        }
                    }
                }
                #endregion
            }

            if (defaultValue == DBNull.Value)
            {
                m_noDefaultValue = true;
            }

            return(defaultValue);
        }
Esempio n. 3
0
 public virtual IList <CustomAttributeData> GetCustomAttributesData()
 {
     return(CustomAttributeData.GetCustomAttributes(this));
 }
        private object GetDefaultValueInternal(bool raw)
        {
            if (this.m_noDefaultValue)
            {
                return(DBNull.Value);
            }
            object obj = null;

            if (this.ParameterType == typeof(DateTime))
            {
                if (raw)
                {
                    CustomAttributeTypedArgument customAttributeTypedArgument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0);
                    if (customAttributeTypedArgument.ArgumentType != null)
                    {
                        return(new DateTime((long)customAttributeTypedArgument.Value));
                    }
                }
                else
                {
                    object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false);
                    if (customAttributes != null && customAttributes.Length != 0)
                    {
                        return(((DateTimeConstantAttribute)customAttributes[0]).Value);
                    }
                }
            }
            if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef))
            {
                obj = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw);
            }
            if (obj == DBNull.Value)
            {
                if (raw)
                {
                    using (IEnumerator <CustomAttributeData> enumerator = CustomAttributeData.GetCustomAttributes(this).GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            CustomAttributeData customAttributeData = enumerator.Current;
                            Type declaringType = customAttributeData.Constructor.DeclaringType;
                            if (declaringType == typeof(DateTimeConstantAttribute))
                            {
                                obj = DateTimeConstantAttribute.GetRawDateTimeConstant(customAttributeData);
                            }
                            else if (declaringType == typeof(DecimalConstantAttribute))
                            {
                                obj = DecimalConstantAttribute.GetRawDecimalConstant(customAttributeData);
                            }
                            else if (declaringType.IsSubclassOf(RuntimeParameterInfo.s_CustomConstantAttributeType))
                            {
                                obj = CustomConstantAttribute.GetRawConstant(customAttributeData);
                            }
                        }
                        goto IL_1A7;
                    }
                }
                object[] customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_CustomConstantAttributeType, false);
                if (customAttributes2.Length != 0)
                {
                    obj = ((CustomConstantAttribute)customAttributes2[0]).Value;
                }
                else
                {
                    customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_DecimalConstantAttributeType, false);
                    if (customAttributes2.Length != 0)
                    {
                        obj = ((DecimalConstantAttribute)customAttributes2[0]).Value;
                    }
                }
            }
IL_1A7:
            if (obj == DBNull.Value)
            {
                this.m_noDefaultValue = true;
            }
            return(obj);
        }
Esempio n. 5
0
        internal object GetDefaultValue(bool raw)
        {
            object missing = null;

            if (!this.m_noDefaultValue)
            {
                if (this.ParameterType == typeof(DateTime))
                {
                    if (raw)
                    {
                        CustomAttributeTypedArgument argument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0);
                        if (argument.ArgumentType != null)
                        {
                            return(new DateTime((long)argument.Value));
                        }
                    }
                    else
                    {
                        object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false);
                        if ((customAttributes != null) && (customAttributes.Length != 0))
                        {
                            return(((DateTimeConstantAttribute)customAttributes[0]).Value);
                        }
                    }
                }
                if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef))
                {
                    missing = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw);
                }
                if (missing == DBNull.Value)
                {
                    if (raw)
                    {
                        IList <CustomAttributeData>  attrs     = CustomAttributeData.GetCustomAttributes(this);
                        CustomAttributeTypedArgument argument2 = CustomAttributeData.Filter(attrs, s_CustomConstantAttributeType, "Value");
                        if (argument2.ArgumentType == null)
                        {
                            argument2 = CustomAttributeData.Filter(attrs, s_DecimalConstantAttributeType, "Value");
                            if (argument2.ArgumentType == null)
                            {
                                for (int i = 0; i < attrs.Count; i++)
                                {
                                    if (attrs[i].Constructor.DeclaringType == s_DecimalConstantAttributeType)
                                    {
                                        ParameterInfo[] parameters = attrs[i].Constructor.GetParameters();
                                        if (parameters.Length != 0)
                                        {
                                            if (parameters[2].ParameterType == typeof(uint))
                                            {
                                                IList <CustomAttributeTypedArgument> constructorArguments = attrs[i].ConstructorArguments;
                                                CustomAttributeTypedArgument         argument3            = constructorArguments[4];
                                                int lo = (int)((uint)argument3.Value);
                                                CustomAttributeTypedArgument argument4 = constructorArguments[3];
                                                int mid = (int)((uint)argument4.Value);
                                                CustomAttributeTypedArgument argument5 = constructorArguments[2];
                                                int hi = (int)((uint)argument5.Value);
                                                CustomAttributeTypedArgument argument6 = constructorArguments[1];
                                                byte num5 = (byte)argument6.Value;
                                                CustomAttributeTypedArgument argument7 = constructorArguments[0];
                                                byte scale = (byte)argument7.Value;
                                                argument2 = new CustomAttributeTypedArgument(new decimal(lo, mid, hi, num5 != 0, scale));
                                            }
                                            else
                                            {
                                                IList <CustomAttributeTypedArgument> list3     = attrs[i].ConstructorArguments;
                                                CustomAttributeTypedArgument         argument8 = list3[4];
                                                int num7 = (int)argument8.Value;
                                                CustomAttributeTypedArgument argument9 = list3[3];
                                                int num8 = (int)argument9.Value;
                                                CustomAttributeTypedArgument argument10 = list3[2];
                                                int num9 = (int)argument10.Value;
                                                CustomAttributeTypedArgument argument11 = list3[1];
                                                byte num10 = (byte)argument11.Value;
                                                CustomAttributeTypedArgument argument12 = list3[0];
                                                byte num11 = (byte)argument12.Value;
                                                argument2 = new CustomAttributeTypedArgument(new decimal(num7, num8, num9, num10 != 0, num11));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (argument2.ArgumentType != null)
                        {
                            missing = argument2.Value;
                        }
                    }
                    else
                    {
                        object[] objArray2 = this.GetCustomAttributes(s_CustomConstantAttributeType, false);
                        if (objArray2.Length != 0)
                        {
                            missing = ((CustomConstantAttribute)objArray2[0]).Value;
                        }
                        else
                        {
                            objArray2 = this.GetCustomAttributes(s_DecimalConstantAttributeType, false);
                            if (objArray2.Length != 0)
                            {
                                missing = ((DecimalConstantAttribute)objArray2[0]).Value;
                            }
                        }
                    }
                }
                if ((missing == DBNull.Value) && base.IsOptional)
                {
                    missing = Type.Missing;
                }
            }
            return(missing);
        }
Esempio n. 6
0
        private object GetDefaultValueInternal(bool raw)
        {
            if (this.m_noDefaultValue)
            {
                return((object)DBNull.Value);
            }
            object obj = (object)null;

            if (this.ParameterType == typeof(DateTime))
            {
                if (raw)
                {
                    CustomAttributeTypedArgument attributeTypedArgument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes((ParameterInfo)this), typeof(DateTimeConstantAttribute), 0);
                    if (attributeTypedArgument.ArgumentType != (Type)null)
                    {
                        return((object)new DateTime((long)attributeTypedArgument.Value));
                    }
                }
                else
                {
                    object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false);
                    if (customAttributes != null && customAttributes.Length != 0)
                    {
                        return(((CustomConstantAttribute)customAttributes[0]).Value);
                    }
                }
            }
            if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef))
            {
                obj = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw);
            }
            if (obj == DBNull.Value)
            {
                if (raw)
                {
                    foreach (CustomAttributeData customAttribute in (IEnumerable <CustomAttributeData>)CustomAttributeData.GetCustomAttributes((ParameterInfo)this))
                    {
                        Type declaringType = customAttribute.Constructor.DeclaringType;
                        if (declaringType == typeof(DateTimeConstantAttribute))
                        {
                            obj = (object)DateTimeConstantAttribute.GetRawDateTimeConstant(customAttribute);
                        }
                        else if (declaringType == typeof(DecimalConstantAttribute))
                        {
                            obj = (object)DecimalConstantAttribute.GetRawDecimalConstant(customAttribute);
                        }
                        else if (declaringType.IsSubclassOf(RuntimeParameterInfo.s_CustomConstantAttributeType))
                        {
                            obj = CustomConstantAttribute.GetRawConstant(customAttribute);
                        }
                    }
                }
                else
                {
                    object[] customAttributes1 = this.GetCustomAttributes(RuntimeParameterInfo.s_CustomConstantAttributeType, false);
                    if (customAttributes1.Length != 0)
                    {
                        obj = ((CustomConstantAttribute)customAttributes1[0]).Value;
                    }
                    else
                    {
                        object[] customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_DecimalConstantAttributeType, false);
                        if (customAttributes2.Length != 0)
                        {
                            obj = (object)((DecimalConstantAttribute)customAttributes2[0]).Value;
                        }
                    }
                }
            }
            if (obj == DBNull.Value)
            {
                this.m_noDefaultValue = true;
            }
            return(obj);
        }