Exemple #1
0
        public Property(CustomTypeBase ct, string name, Type type)
        {
            this.CustomTypeBase = ct;
            this.Name           = name;
            this.Type           = type;
            this.FieldName      = "_" + name;

            PropertyBuilder propertyBuilder = ct.TypeBuilder.DefineProperty(
                name,
                PropertyAttributes.HasDefault,
                type,
                null);

            PropertyBuilder = propertyBuilder;
        }
Exemple #2
0
        public SimpleProperty(CustomTypeBase ct, string name, Type type) : base(ct, name, type)
        {
            var field = ct.TypeBuilder.DefineField(this.FieldName, type, FieldAttributes.Private);

            this.FieldInfo = field;

            MethodAttributes getSetAttr = MethodAttributes.Public |
                                          MethodAttributes.SpecialName | MethodAttributes.HideBySig;


            MethodBuilder propertyGetAccessor = ct.TypeBuilder.DefineMethod(
                "get_" + name,
                getSetAttr,
                type,
                Type.EmptyTypes);

            this.PropertyGetter = propertyGetAccessor;

            var fieldGetIL = propertyGetAccessor.GetILGenerator();

            fieldGetIL.DeclareLocal(type);
            fieldGetIL.Emit(OpCodes.Ldarg_0);
            fieldGetIL.Emit(OpCodes.Ldfld, field);
            fieldGetIL.Emit(OpCodes.Ret);

            MethodBuilder propertySetAccessor = ct.TypeBuilder.DefineMethod(
                "set_" + name,
                getSetAttr,
                null,
                new Type[] { type });

            this.PropertySetter = propertySetAccessor;

            var fieldSetIL = propertySetAccessor.GetILGenerator();

            fieldSetIL.Emit(OpCodes.Ldarg_0);
            fieldSetIL.Emit(OpCodes.Ldarg_1);
            fieldSetIL.Emit(OpCodes.Stfld, field);
            fieldSetIL.Emit(OpCodes.Ret);

            PropertyBuilder.SetGetMethod(propertyGetAccessor);
            PropertyBuilder.SetSetMethod(propertySetAccessor);
        }
Exemple #3
0
 public Method(CustomTypeBase onCustomType)
 {
     this.CustomType = onCustomType;
 }