Esempio n. 1
0
        private PropertyDefinition GenerateProperty(PropertyDefinition property)
        {
            const MethodAttributes attr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName |
                                          MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final;

            var p = TypeFactory.CreateProperty(property.Name, attr, property.PropertyType, _handler);

            var getter = new IlBuilder(p.GetMethod.Body);

            getter.DeclareLocal(property.PropertyType);
            getter.LoadArg(0);
            getter.LoadField(_result.Fields[0]);
            getter.Call(_model.Properties[_startIndex].GetMethod);
            getter.SetLoc(0);
            var i = getter.Processor.Create(OpCodes.Ldloc_0);

            getter.Br_S(i);
            getter.Instructions.Add(i);
            getter.Return();
            getter.Append();

            var setter = new IlBuilder(p.SetMethod.Body);

            setter.LoadArg(0);
            setter.LoadField(_result.Fields[0]);
            setter.LoadArg(1);
            setter.Call(_model.Properties[_startIndex].SetMethod);
            setter.Return();
            setter.Append();

            _startIndex++;
            return(p);
        }
Esempio n. 2
0
        private void ProcessPropertySetNormalCompareString(IlBuilder processor)
        {
            processor.DeclareLocal(_handler.BoolType);
            processor.LoadArg(1);
            processor.LoadArg(0);
            processor.LoadField(_pi.FieldDefinition);
            var mi = _handler.TypeDict[_pi.PropertyDefinition.PropertyType.FullName];

            processor.Call(mi);
            processor.LoadInt(0);
            processor.Ceq();
            processor.SetLoc(0);
            processor.LoadLoc(0);
            processor.BrTrue_S(_pi.PropertyDefinition.SetMethod.Body.Instructions.LastItem());
        }
Esempio n. 3
0
        private void GenerateGetValue(TypeDefinition type, MemberHandler member, TypeReference memberType)
        {
            var method = new MethodDefinition("GetValue", CtMethodAttr, _handler.ObjectType);

            method.Parameters.Add(new ParameterDefinition("obj", ParameterAttributes.None, _handler.ObjectType));
            var processor = new IlBuilder(method.Body);

            processor.DeclareLocal(_handler.ObjectType);
            processor.LoadArg(1).Cast(_model);
            processor.GetMember(member, _handler);
            if (member.MemberInfo.MemberType.IsValueType)
            {
                processor.Box(memberType);
            }
            processor.SetLoc(0);
            processor.LoadLoc(0);
            processor.Return();
            processor.Append();
            type.Methods.Add(method);
        }