Exemple #1
0
 private CustomAttributeData(RuntimeModule scope, CustomAttributeRecord caRecord)
 {
     this.m_scope = scope;
     this.m_ctor  = (RuntimeConstructorInfo)RuntimeType.GetMethodBase(scope, caRecord.tkCtor);
     ParameterInfo[] parametersNoCopy = this.m_ctor.GetParametersNoCopy();
     this.m_ctorParams = new CustomAttributeCtorParameter[parametersNoCopy.Length];
     for (int i = 0; i < parametersNoCopy.Length; i++)
     {
         this.m_ctorParams[i] = new CustomAttributeCtorParameter(CustomAttributeData.InitCustomAttributeType((RuntimeType)parametersNoCopy[i].ParameterType));
     }
     FieldInfo[]    fields     = this.m_ctor.DeclaringType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     PropertyInfo[] properties = this.m_ctor.DeclaringType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     this.m_namedParams = new CustomAttributeNamedParameter[properties.Length + fields.Length];
     for (int j = 0; j < fields.Length; j++)
     {
         this.m_namedParams[j] = new CustomAttributeNamedParameter(fields[j].Name, CustomAttributeEncoding.Field, CustomAttributeData.InitCustomAttributeType((RuntimeType)fields[j].FieldType));
     }
     for (int k = 0; k < properties.Length; k++)
     {
         this.m_namedParams[k + fields.Length] = new CustomAttributeNamedParameter(properties[k].Name, CustomAttributeEncoding.Property, CustomAttributeData.InitCustomAttributeType((RuntimeType)properties[k].PropertyType));
     }
     this.m_members = new MemberInfo[fields.Length + properties.Length];
     fields.CopyTo(this.m_members, 0);
     properties.CopyTo(this.m_members, fields.Length);
     CustomAttributeEncodedArgument.ParseAttributeArguments(caRecord.blob, ref this.m_ctorParams, ref this.m_namedParams, this.m_scope);
 }
Exemple #2
0
        internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncodedArgument encodedArg)
        {
            CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType;

            switch (encodedType)
            {
            case CustomAttributeEncoding.Undefined:
                throw new ArgumentException("encodedArg");

            case CustomAttributeEncoding.Enum:
                RuntimeModule       scope1 = scope;
                CustomAttributeType customAttributeType = encodedArg.CustomAttributeType;
                string enumName = customAttributeType.EnumName;
                this.m_argumentType = (Type)CustomAttributeTypedArgument.ResolveType(scope1, enumName);
                long primitiveValue = encodedArg.PrimitiveValue;
                customAttributeType = encodedArg.CustomAttributeType;
                int num = (int)customAttributeType.EncodedEnumType;
                this.m_value = CustomAttributeTypedArgument.EncodedValueToRawValue(primitiveValue, (CustomAttributeEncoding)num);
                break;

            case CustomAttributeEncoding.String:
                this.m_argumentType = typeof(string);
                this.m_value        = (object)encodedArg.StringValue;
                break;

            case CustomAttributeEncoding.Type:
                this.m_argumentType = typeof(Type);
                this.m_value        = (object)null;
                if (encodedArg.StringValue == null)
                {
                    break;
                }
                this.m_value = (object)CustomAttributeTypedArgument.ResolveType(scope, encodedArg.StringValue);
                break;

            case CustomAttributeEncoding.Array:
                CustomAttributeEncoding encodedArrayType = encodedArg.CustomAttributeType.EncodedArrayType;
                this.m_argumentType = (encodedArrayType != CustomAttributeEncoding.Enum ? CustomAttributeTypedArgument.CustomAttributeEncodingToType(encodedArrayType) : (Type)CustomAttributeTypedArgument.ResolveType(scope, encodedArg.CustomAttributeType.EnumName)).MakeArrayType();
                if (encodedArg.ArrayValue == null)
                {
                    this.m_value = (object)null;
                    break;
                }
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[encodedArg.ArrayValue.Length];
                for (int index = 0; index < array.Length; ++index)
                {
                    array[index] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[index]);
                }
                this.m_value = (object)Array.AsReadOnly <CustomAttributeTypedArgument>(array);
                break;

            default:
                this.m_argumentType = CustomAttributeTypedArgument.CustomAttributeEncodingToType(encodedType);
                this.m_value        = CustomAttributeTypedArgument.EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
                break;
            }
        }
 internal static void ParseAttributeArguments(ConstArray attributeBlob, ref CustomAttributeCtorParameter[] customAttributeCtorParameters, ref CustomAttributeNamedParameter[] customAttributeNamedParameters, RuntimeModule customAttributeModule)
 {
     if (customAttributeModule == null)
     {
         throw new ArgumentNullException("customAttributeModule");
     }
     if (customAttributeCtorParameters.Length != 0 || customAttributeNamedParameters.Length != 0)
     {
         CustomAttributeEncodedArgument.ParseAttributeArguments(attributeBlob.Signature, attributeBlob.Length, ref customAttributeCtorParameters, ref customAttributeNamedParameters, (RuntimeAssembly)customAttributeModule.Assembly);
     }
 }
 public CustomAttributeNamedParameter(string argumentName, CustomAttributeEncoding fieldOrProperty, CustomAttributeType type)
 {
     if (argumentName == null)
     {
         throw new ArgumentNullException("argumentName");
     }
     this.m_argumentName = argumentName;
     this.m_fieldOrProperty = fieldOrProperty;
     this.m_padding = fieldOrProperty;
     this.m_type = type;
     this.m_encodedArgument = new CustomAttributeEncodedArgument();
 }
 public CustomAttributeNamedParameter(string argumentName, CustomAttributeEncoding fieldOrProperty, CustomAttributeType type)
 {
     if (argumentName == null)
     {
         throw new ArgumentNullException("argumentName");
     }
     this.m_argumentName    = argumentName;
     this.m_fieldOrProperty = fieldOrProperty;
     this.m_padding         = fieldOrProperty;
     this.m_type            = type;
     this.m_encodedArgument = new CustomAttributeEncodedArgument();
 }
        internal CustomAttributeTypedArgument(Module scope, CustomAttributeEncodedArgument encodedArg)
        {
            CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType;
            switch (encodedType)
            {
                case CustomAttributeEncoding.Undefined:
                    throw new ArgumentException("encodedArg");

                case CustomAttributeEncoding.Enum:
                    this.m_argumentType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                    this.m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
                    return;

                case CustomAttributeEncoding.String:
                    this.m_argumentType = typeof(string);
                    this.m_value = encodedArg.StringValue;
                    return;

                case CustomAttributeEncoding.Type:
                    this.m_argumentType = typeof(Type);
                    this.m_value = null;
                    if (encodedArg.StringValue != null)
                    {
                        this.m_value = ResolveType(scope, encodedArg.StringValue);
                        return;
                    }
                    break;

                case CustomAttributeEncoding.Array:
                {
                    Type type;
                    encodedType = encodedArg.CustomAttributeType.EncodedArrayType;
                    if (encodedType == CustomAttributeEncoding.Enum)
                    {
                        type = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                    }
                    else
                    {
                        type = CustomAttributeEncodingToType(encodedType);
                    }
                    this.m_argumentType = type.MakeArrayType();
                    if (encodedArg.ArrayValue == null)
                    {
                        this.m_value = null;
                        return;
                    }
                    CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[encodedArg.ArrayValue.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[i]);
                    }
                    this.m_value = Array.AsReadOnly<CustomAttributeTypedArgument>(array);
                    return;
                }
                default:
                    this.m_argumentType = CustomAttributeEncodingToType(encodedType);
                    this.m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
                    break;
            }
        }
Exemple #7
0
        internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncodedArgument encodedArg)
        {
            CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType;

            if (encodedType == CustomAttributeEncoding.Undefined)
                throw new ArgumentException("encodedArg");

            else if (encodedType == CustomAttributeEncoding.Enum)
            {
                m_argumentType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
            }
            else if (encodedType == CustomAttributeEncoding.String)
            {
                m_argumentType = typeof(string);
                m_value = encodedArg.StringValue;
            }
            else if (encodedType == CustomAttributeEncoding.Type)
            {
                m_argumentType = typeof(Type);
                
                m_value = null;

                if (encodedArg.StringValue != null)
                    m_value = ResolveType(scope, encodedArg.StringValue);
            }
            else if (encodedType == CustomAttributeEncoding.Array)
            {                
                encodedType = encodedArg.CustomAttributeType.EncodedArrayType;
                Type elementType;
                
                if (encodedType == CustomAttributeEncoding.Enum)
                {
                    elementType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                }
                else
                {
                    elementType = CustomAttributeEncodingToType(encodedType);
                }

                m_argumentType = elementType.MakeArrayType();
        
                if (encodedArg.ArrayValue == null)
                {
                    m_value = null;                    
                }
                else
                {
                    CustomAttributeTypedArgument[] arrayValue = new CustomAttributeTypedArgument[encodedArg.ArrayValue.Length];
                    for (int i = 0; i < arrayValue.Length; i++)
                        arrayValue[i] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[i]);

                    m_value = Array.AsReadOnly(arrayValue);
                }
            }
            else
            {
                m_argumentType = CustomAttributeEncodingToType(encodedType);
                m_value = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
            }
        }
Exemple #8
0
 public CustomAttributeCtorParameter(CustomAttributeType type)
 {
     m_type = type;
     m_encodedArgument = new CustomAttributeEncodedArgument();
 }
Exemple #9
0
        public CustomAttributeNamedParameter(string argumentName, CustomAttributeEncoding fieldOrProperty, CustomAttributeType type)
        {
            if (argumentName == null)
                throw new ArgumentNullException(nameof(argumentName));
            Contract.EndContractBlock();

            m_argumentName = argumentName;
            m_fieldOrProperty = fieldOrProperty;
            m_padding = fieldOrProperty;
            m_type = type;
            m_encodedArgument = new CustomAttributeEncodedArgument();
        }
        // Token: 0x0600443D RID: 17469 RVA: 0x000FA6D0 File Offset: 0x000F88D0
        internal CustomAttributeTypedArgument(RuntimeModule scope, CustomAttributeEncodedArgument encodedArg)
        {
            CustomAttributeEncoding customAttributeEncoding = encodedArg.CustomAttributeType.EncodedType;

            if (customAttributeEncoding == CustomAttributeEncoding.Undefined)
            {
                throw new ArgumentException("encodedArg");
            }
            if (customAttributeEncoding == CustomAttributeEncoding.Enum)
            {
                this.m_argumentType = CustomAttributeTypedArgument.ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                this.m_value        = CustomAttributeTypedArgument.EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
                return;
            }
            if (customAttributeEncoding == CustomAttributeEncoding.String)
            {
                this.m_argumentType = typeof(string);
                this.m_value        = encodedArg.StringValue;
                return;
            }
            if (customAttributeEncoding == CustomAttributeEncoding.Type)
            {
                this.m_argumentType = typeof(Type);
                this.m_value        = null;
                if (encodedArg.StringValue != null)
                {
                    this.m_value = CustomAttributeTypedArgument.ResolveType(scope, encodedArg.StringValue);
                    return;
                }
            }
            else if (customAttributeEncoding == CustomAttributeEncoding.Array)
            {
                customAttributeEncoding = encodedArg.CustomAttributeType.EncodedArrayType;
                Type type;
                if (customAttributeEncoding == CustomAttributeEncoding.Enum)
                {
                    type = CustomAttributeTypedArgument.ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                }
                else
                {
                    type = CustomAttributeTypedArgument.CustomAttributeEncodingToType(customAttributeEncoding);
                }
                this.m_argumentType = type.MakeArrayType();
                if (encodedArg.ArrayValue == null)
                {
                    this.m_value = null;
                    return;
                }
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[encodedArg.ArrayValue.Length];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[i]);
                }
                this.m_value = Array.AsReadOnly <CustomAttributeTypedArgument>(array);
                return;
            }
            else
            {
                this.m_argumentType = CustomAttributeTypedArgument.CustomAttributeEncodingToType(customAttributeEncoding);
                this.m_value        = CustomAttributeTypedArgument.EncodedValueToRawValue(encodedArg.PrimitiveValue, customAttributeEncoding);
            }
        }
Exemple #11
0
 public CustomAttributeCtorParameter(CustomAttributeType type)
 {
     this.m_type            = type;
     this.m_encodedArgument = new CustomAttributeEncodedArgument();
 }
Exemple #12
0
        internal CustomAttributeTypedArgument(Module scope, CustomAttributeEncodedArgument encodedArg)
        {
            CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType;

            switch (encodedType)
            {
            case CustomAttributeEncoding.Undefined:
                throw new ArgumentException("encodedArg");

            case CustomAttributeEncoding.Enum:
                this.m_argumentType = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                this.m_value        = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedArg.CustomAttributeType.EncodedEnumType);
                return;

            case CustomAttributeEncoding.String:
                this.m_argumentType = typeof(string);
                this.m_value        = encodedArg.StringValue;
                return;

            case CustomAttributeEncoding.Type:
                this.m_argumentType = typeof(Type);
                this.m_value        = null;
                if (encodedArg.StringValue != null)
                {
                    this.m_value = ResolveType(scope, encodedArg.StringValue);
                    return;
                }
                break;

            case CustomAttributeEncoding.Array:
            {
                Type type;
                encodedType = encodedArg.CustomAttributeType.EncodedArrayType;
                if (encodedType == CustomAttributeEncoding.Enum)
                {
                    type = ResolveType(scope, encodedArg.CustomAttributeType.EnumName);
                }
                else
                {
                    type = CustomAttributeEncodingToType(encodedType);
                }
                this.m_argumentType = type.MakeArrayType();
                if (encodedArg.ArrayValue == null)
                {
                    this.m_value = null;
                    return;
                }
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[encodedArg.ArrayValue.Length];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = new CustomAttributeTypedArgument(scope, encodedArg.ArrayValue[i]);
                }
                this.m_value = Array.AsReadOnly <CustomAttributeTypedArgument>(array);
                return;
            }

            default:
                this.m_argumentType = CustomAttributeEncodingToType(encodedType);
                this.m_value        = EncodedValueToRawValue(encodedArg.PrimitiveValue, encodedType);
                break;
            }
        }