internal static CustomAttributeDataMirror[] Create(VirtualMachine vm, CattrInfo[] info)
        {
            var res = new CustomAttributeDataMirror [info.Length];

            for (int i = 0; i < info.Length; ++i)
            {
                CattrInfo    attr      = info [i];
                MethodMirror ctor      = vm.GetMethod(attr.ctor_id);
                var          ctor_args = new object [attr.ctor_args.Length];
                for (int j = 0; j < ctor_args.Length; ++j)
                {
                    ctor_args [j] = CreateArg(vm, attr.ctor_args [j]);
                }
                var named_args = new object [attr.named_args.Length];
                for (int j = 0; j < named_args.Length; ++j)
                {
                    CattrNamedArgInfo arg = attr.named_args [j];
                    CustomAttributeTypedArgumentMirror val;

                    val = CreateArg(vm, arg.value);

                    if (arg.is_property)
                    {
                        foreach (var prop in ctor.DeclaringType.GetProperties())
                        {
                            if (prop.Id == arg.id)
                            {
                                named_args [j] = new CustomAttributeNamedArgumentMirror(prop, null, val);
                            }
                        }
                    }
                    else
                    {
                        foreach (var field in ctor.DeclaringType.GetFields())
                        {
                            if (field.Id == arg.id)
                            {
                                named_args [j] = new CustomAttributeNamedArgumentMirror(null, field, val);
                            }
                        }
                    }
                    if (named_args [j] == null)
                    {
                        throw new NotImplementedException();
                    }
                }
                res [i] = new CustomAttributeDataMirror(vm.GetMethod(attr.ctor_id), ctor_args, named_args);
            }

            return(res);
        }
Beispiel #2
0
        CustomAttributeDataMirror[] GetCAttrs(TypeMirror type, bool inherit)
        {
            // FIXME: Handle inherit
            if (cattrs == null)
            {
                CattrInfo[] info = vm.conn.Type_GetFieldCustomAttributes(DeclaringType.Id, id, 0, false);
                cattrs = CustomAttributeDataMirror.Create(vm, info);
            }
            var res = new List <CustomAttributeDataMirror> ();

            foreach (var attr in cattrs)
            {
                if (type == null || attr.Constructor.DeclaringType == type)
                {
                    res.Add(attr);
                }
            }
            return(res.ToArray());
        }