Пример #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);
        }