コード例 #1
0
 public EmittedMethod AddGetter()
 {
     if (_getter != null) throw new InvalidOperationException("Getter already assigned");
     _getter = this.TargetClass.DefineMethod(String.Format("get_{0}", this.Name));
     if (IsStatic) _getter.IncludeAttributes(MethodAttributes.Static);
     _getter.IncludeAttributes(MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Final | MethodAttributes.NewSlot);
     _getter.ReturnType = this.PropertyType;
     return _getter;
 }
コード例 #2
0
        protected internal override void OnCompile()
        {
            this.Builder = this.TargetClass.Builder.DefineProperty(this.Name
                , this.Attributes
                , this.PropertyType.Target
                , this.ParameterTypes);
            if (_getter == null && _boundField != null)
            {
                _getter = AddGetter();
                _getter.DefineMethodBody((m,il) =>
                    {
                        il.LoadArg_0();
                        _boundField.LoadValue(il);
                    });
            }
            if (_getter != null)
            {
                if (!_getter.IsCompiled) _getter.Compile();
                Builder.SetGetMethod(_getter.Builder);
            }
            if (_setter == null && _boundField != null)
            {
                _setter = AddSetter();

                _setter.DefineMethodBody((m, il) =>
                    {
                        il.LoadArg_0();
                        il.LoadArg_1();
                        _boundField.StoreValue(il);
                    });
            }
            if (_setter != null)
            {
                if (!_setter.IsCompiled) _setter.Compile();
                Builder.SetSetMethod(_setter.Builder);
            }
        }