System.Reflection.CustomAttributeData.InitCustomAttributeType C# (CSharp) Method

InitCustomAttributeType() private static method

private static InitCustomAttributeType ( Type parameterType, Module scope ) : CustomAttributeType
parameterType Type
scope Module
return CustomAttributeType
        private static CustomAttributeType InitCustomAttributeType(Type parameterType, Module scope)
        {
            CustomAttributeEncoding encodedType = CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            CustomAttributeEncoding encodedArrayType = CustomAttributeEncoding.Undefined;
            CustomAttributeEncoding encodedEnumType = CustomAttributeEncoding.Undefined;
            string enumName = null;

            if (encodedType == CustomAttributeEncoding.Array)
            {
                parameterType = parameterType.GetElementType();
                encodedArrayType = CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            }

            if (encodedType == CustomAttributeEncoding.Enum || encodedArrayType == CustomAttributeEncoding.Enum)
            {
                encodedEnumType = TypeToCustomAttributeEncoding(Enum.GetUnderlyingType(parameterType));

                if (parameterType.Module == scope)
                    enumName = parameterType.FullName;
                else
                    enumName = parameterType.AssemblyQualifiedName;
            }

            return new CustomAttributeType(encodedType, encodedArrayType, encodedEnumType, enumName);
        }
        private static IList<CustomAttributeData> GetCustomAttributes(Module module, int tkTarget)

Usage Example

Esempio n. 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);
 }