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);
		}
示例#2
0
        /// <summary>
        /// Creates / gets the correct field for the generated class which represents the logicbase class for a given
        /// MData interface.
        /// </summary>
        /// <param name="generatedFields"></param>
        /// <param name="typeBuilder"></param>
        /// <param name="interfaceToImplement"></param>
        /// <param name="isMethodData"></param>
        /// <param name="logicClassType"></param>
        /// <returns></returns>
        private static FieldBuilder CreateLogicBaseField(Dictionary<Type, FieldBuilder> generatedFields, TypeBuilderHelper typeBuilder, Type interfaceToImplement, bool isMethodData, ref Type logicClassType)
        {
            //not all interfaces implemented by domainType necesarly have the MData attribute
            //they could also have the MDataMethod attribute meaning that they will be implemented
            //by the same logic class as the MDataMethod attribute's parameter
            //if the interface is a MDataMethod interface, assign it to the linked logicClass
            if (isMethodData)
            {
                var linkedInterfaceType = interfaceToImplement.GetAttributes<MDataMethodAttribute>().First().GetLinkedInterfaceType();
                logicClassType = generatedFields[linkedInterfaceType].FieldType;
                return generatedFields[linkedInterfaceType];
            }

            return typeBuilder.DefineField(GetFieldFullName(logicClassType), logicClassType,FieldAttributes.FamORAssem);
        }