コード例 #1
0
        private static void ctx_CustomAttributeDataLoadEvent(object sender, CustomAttributeDataEventArgs e)
        {
            IEnumerable <System.Reflection.CustomAttributeData> attrs;

            if (e.Member != null)
            {
                attrs = e.Member.GetCustomAttributesData();
            }
            else if (e.Type != null)
            {
                attrs = e.Type.GetCustomAttributesData();
            }
            else if (e.Parameter != null)
            {
                attrs = e.Parameter.GetCustomAttributesData();
            }
            else if (e.Assembly != null)
            {
                attrs = e.Assembly.GetCustomAttributesData();
            }
            else if (e.Module != null)
            {
                attrs = e.Module.GetCustomAttributesData();
            }
            else
            {
                throw new ArgumentException("Custom attribute data event with no native member?");
            }

            e.CustomAttributeData = attrs.Select(attr => Tuple.Create(
                                                     attr.Constructor.NewWrapper(e.Context),
                                                     attr.ConstructorArguments.Select(cArg => CILCustomAttributeFactory.NewTypedArgument((cArg.ArgumentType.NewWrapperAsType(e.Context)), cArg.Value)),
                                                     attr.NamedArguments.Select(nArg => CILCustomAttributeFactory.NewNamedArgument((nArg.MemberInfo is System.Reflection.PropertyInfo ? (CILElementForNamedCustomAttribute)((System.Reflection.PropertyInfo)nArg.MemberInfo).NewWrapper(e.Context) : ((System.Reflection.FieldInfo)nArg.MemberInfo).NewWrapper(e.Context)), CILCustomAttributeFactory.NewTypedArgument(nArg.TypedValue.ArgumentType.NewWrapperAsType(e.Context), nArg.TypedValue.Value)))
                                                     ));
        }
コード例 #2
0
ファイル: Exceptions.cs プロジェクト: PlumpMath/CAM
 internal CustomAttributeDataLoadException(CustomAttributeDataEventArgs args)
     : base("Reflection context could not load custom attribute data.")
 {
     this._args = args;
 }