Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 CattrInfo[] ReadCattrs(PacketReader r)
 {
     CattrInfo[] res = new CattrInfo[r.ReadInt()];
     for (int i = 0; i < res.Length; ++i)
     {
         CattrInfo info = new CattrInfo();
         info.ctor_id = r.ReadId();
         info.ctor_args = new ValueImpl[r.ReadInt()];
         for (int j = 0; j < info.ctor_args.Length; ++j)
         {
             info.ctor_args[j] = r.ReadValue();
         }
         info.named_args = new CattrNamedArgInfo[r.ReadInt()];
         for (int j = 0; j < info.named_args.Length; ++j)
         {
             CattrNamedArgInfo arg = new CattrNamedArgInfo();
             int arg_type = r.ReadByte();
             arg.is_property = arg_type == 0x54;
             arg.id = r.ReadId();
             arg.value = r.ReadValue();
             info.named_args[j] = arg;
         }
         res[i] = info;
     }
     return res;
 }