Example #1
0
        public void DefinePropertyReadOnlyWrapper(string name, Type propertyType)
        {
            PropertyDefine def   = DefineProperty(name, propertyType);
            var            field = DefineField(string.Format("_{0}", name), propertyType);

            InitGetProperty(def, field);
        }
Example #2
0
        private void InitGetProperty(PropertyDefine def, FieldBuilder field)
        {
            //get
            var g = def.GetMethod;

            g.LoadParameter(0);/// 在一个属性实例中,参数0是实例obj
            g.LoadField(field);
            g.Return();
        }
Example #3
0
        private void InitSetProperty(PropertyDefine def, FieldBuilder field)
        {
            //set
            var g = def.SetMethod;

            g.LoadParameter(0);
            g.Assign(field, () =>
            {
                g.LoadParameter(1);//在属性的设置方法中,第二个参数是value
            });
            g.Return();
        }