Ejemplo n.º 1
0
        private void CreateProperty(TypeBuilderHelper typeBuilderHelper)
        {
            var dbObjectContainerField  = typeBuilderHelper.DefineField("dbObjectContainer", typeof(DbObjectContainer), FieldAttributes.Private);
            var objectContainerProperty = typeBuilderHelper.TypeBuilder.DefineProperty("DbObjectContainer",
                                                                                       PropertyAttributes.HasDefault,
                                                                                       typeof(DbObjectContainer),
                                                                                       new[] { typeof(DbObjectContainer) });
            var attributes = MethodAttributes.Public | MethodAttributes.SpecialName |
                             MethodAttributes.HideBySig;
            var objectContainerGetMethod = typeBuilderHelper.DefineMethod("get_DbObjectContainer",
                                                                          attributes, typeof(DbObjectContainer), Type.EmptyTypes);
            var objectContainerGetMethodEmit = objectContainerGetMethod.Emitter;

            objectContainerGetMethodEmit
            .ldarg_0
            .ldfld(dbObjectContainerField)
            .ret();

            var objectContainerSetMethod = typeBuilderHelper.DefineMethod("set_DbObjectContainer",
                                                                          attributes, null, typeof(DbObjectContainer));
            var objectContainerSetMethodEmit = objectContainerSetMethod.Emitter;

            objectContainerSetMethodEmit
            .ldarg_0
            .ldarg_1
            .stfld(dbObjectContainerField)
            .ret();
            objectContainerProperty.SetGetMethod(objectContainerGetMethod);
            objectContainerProperty.SetSetMethod(objectContainerSetMethod);
        }