예제 #1
0
        void AppendCustomAttrs(IList <CustomAttributeDataMirror> attrs, TypeMirror type, bool inherit)
        {
#if ENABLE_CECIL
            if (cattrs == null && Metadata != null && !Metadata.HasCustomAttributes)
            {
                cattrs = new CustomAttributeDataMirror [0];
            }
#endif

            if (cattrs == null)
            {
                CattrInfo[] info = vm.conn.Type_GetCustomAttributes(id, 0, false);
                cattrs = CustomAttributeDataMirror.Create(vm, info);
            }

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

            if (inherit && BaseType != null)
            {
                BaseType.AppendCustomAttrs(attrs, type, inherit);
            }
        }
예제 #2
0
        CustomAttributeDataMirror[] GetCAttrs(TypeMirror type, bool inherit)
        {
#if ENABLE_CECIL
            if (cattrs == null && Metadata != null && !Metadata.HasCustomAttributes)
            {
                cattrs = new CustomAttributeDataMirror [0];
            }
#endif

            // 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());
        }
예제 #3
0
        CustomAttributeDataMirror[] GetCAttrs(TypeMirror type)
        {
            vm.CheckProtocolVersion(2, 58);

#if ENABLE_CECIL
            if (cattrs == null && meta != null && !Metadata.HasCustomAttributes)
            {
                cattrs = new CustomAttributeDataMirror [0];
            }
#endif

            if (cattrs == null)
            {
                CattrInfo[] info = vm.conn.Assembly_GetCustomAttributes(id, 0);
                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());
        }
예제 #4
0
        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 List <object> (attr.named_args.Length);
                for (int j = 0; j < attr.named_args.Length; ++j)
                {
                    CattrNamedArgInfo arg = attr.named_args [j];
                    CustomAttributeTypedArgumentMirror val;
                    CustomAttributeNamedArgumentMirror?named_arg = null;

                    val = CreateArg(vm, arg.value);

                    TypeMirror t = ctor.DeclaringType;
                    while (named_arg == null && t != null)
                    {
                        if (arg.is_property)
                        {
                            foreach (var prop in t.GetProperties())
                            {
                                if (prop.Id == arg.id)
                                {
                                    named_arg = new CustomAttributeNamedArgumentMirror(prop, null, val);
                                }
                            }
                        }
                        else if (vm.Version.AtLeast(2, 12))                              // we don't have the field ID before 2.12
                        {
                            foreach (var field in t.GetFields())
                            {
                                if (field.Id == arg.id)
                                {
                                    named_arg = new CustomAttributeNamedArgumentMirror(null, field, val);
                                }
                            }
                        }
                        t = t.BaseType;
                    }

                    if (named_arg.HasValue)
                    {
                        named_args.Add(named_arg.Value);
                    }
                }
                res [i] = new CustomAttributeDataMirror(ctor, ctor_args, named_args.ToArray());
            }

            return(res);
        }
예제 #5
0
        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);

                    TypeMirror t = ctor.DeclaringType;
                    while (named_args [j] == null && t != null)
                    {
                        if (arg.is_property)
                        {
                            foreach (var prop in t.GetProperties())
                            {
                                if (prop.Id == arg.id)
                                {
                                    named_args [j] = new CustomAttributeNamedArgumentMirror(prop, null, val);
                                }
                            }
                        }
                        else
                        {
                            foreach (var field in t.GetFields())
                            {
                                if (field.Id == arg.id)
                                {
                                    named_args [j] = new CustomAttributeNamedArgumentMirror(null, field, val);
                                }
                            }
                        }
                        t = t.BaseType;
                    }
                    if (named_args [j] == null)
                    {
                        throw new NotImplementedException();
                    }
                }
                res [i] = new CustomAttributeDataMirror(ctor, ctor_args, named_args);
            }

            return(res);
        }
예제 #6
0
        CustomAttributeDataMirror[] GetCAttrs(TypeMirror type, bool inherit)
        {
            // FIXME: Handle inherit
            if (cattrs == null)
            {
                CattrInfo[] info = vm.conn.Type_GetCustomAttributes(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());
        }