public EntityData(string classNamespace, string className)
 {
     Namespace = classNamespace;
     ClassName = className;
     Fields = new EntityTypes();
     IsStoredProcedure = false;
 }
Esempio n. 2
0
        /// <summary>
        /// Генерирует тип для работы со справочником
        /// </summary>
        /// <param name="m"></param>
        /// <param name="typeName"></param>
        /// <param name="entityProps"></param>
        private void GenerateType(ModuleBuilder m, String typeName, String databaseTableName, EntityTypes entityProps)
        {
            TypeBuilder t = m.DefineType(typeName, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoClass, typeof(SQLBookSEBase));

            CustomAttributeBuilder attr = new CustomAttributeBuilder(
                typeof(DalClassAttribute).GetConstructor(new Type[] { typeof(string) }),
                new object[] { databaseTableName });
            t.SetCustomAttribute(attr);

            t.DefineDefaultConstructor(MethodAttributes.Public);

            MethodInfo accessorId = t.BaseType.GetMethod("set_Id", new Type[] { typeof(int) });

            //
            //Generate constructor by Id
            //

            ConstructorBuilder ctor = t.DefineConstructor(
                MethodAttributes.Private,
                CallingConventions.Standard,
                new Type[] { typeof(int) });

            ctor.DefineParameter(1, ParameterAttributes.In, "Id");

            ILGenerator genCtor = ctor.GetILGenerator();
            genCtor.Emit(OpCodes.Ldarg_0);
            genCtor.Emit(OpCodes.Call, t.BaseType.GetConstructor(Type.EmptyTypes));
            genCtor.Emit(OpCodes.Nop);
            genCtor.Emit(OpCodes.Nop);
            genCtor.Emit(OpCodes.Ldarg_0);
            genCtor.Emit(OpCodes.Ldarg_1);
            genCtor.Emit(OpCodes.Call, accessorId);
            genCtor.Emit(OpCodes.Nop);
            genCtor.Emit(OpCodes.Ldarg_0);
            genCtor.Emit(OpCodes.Ldarg_1);
            genCtor.Emit(OpCodes.Call, t.BaseType.GetMethod("Load", new Type[] { typeof(int) }));
            genCtor.Emit(OpCodes.Pop);
            genCtor.Emit(OpCodes.Nop);
            genCtor.Emit(OpCodes.Ret);

            //
            //End of generate constructor
            //

            GenerateStaticGet(t, ctor);
            GenerateStaticGetList(t, ctor);

            foreach (EntityType et in entityProps)
            {
                if (!et.IsKey)
                    GenerateProp(t, et.TypeName, et.Name);
            }

            t.CreateType();
        }
Esempio n. 3
0
        /// <summary>
        /// Генерирует класс для работы с хранимыми процедурами
        /// </summary>
        /// <param name="m"></param>
        /// <param name="nameSpace"></param>
        /// <param name="typeName"></param>
        private void GenerateSPType(ModuleBuilder m, string className, string storedProcedureName, EntityTypes entityTypes)
        {
            TypeBuilder t = m.DefineType(className,
                TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoClass,
                null);
            t.DefineDefaultConstructor(MethodAttributes.Public);

            Dictionary<string, Type> dict = new Dictionary<string, Type>();

            foreach (EntityType e in entityTypes)
            {
                dict.Add(e.Name, e.TypeName);
            }

            GenerateStaticMethod(t, "Call", dict, storedProcedureName);

            t.CreateType();
        }