/// <summary> /// Generate code. /// </summary> /// <param name="gen">The specified APGen generation object.</param> public override void Generate(APGen gen) { CodeNamespace cns = gen.GetCodeNamespace(gen.DefaultNamespace); foreach (APGenNamespace ns in Namespaces) { cns.Imports.Add(new CodeNamespaceImport(ns.Import)); } }
/// <summary> /// Generate code. /// </summary> /// <param name="gen">The specified APGen object.</param> public virtual void Generate(APGen gen) { gen.GetCodeNamespace(gen.DefaultNamespace) .Comments .Add(Comment(APResource.GetString(APResource.APGen_DefaultGenerated, GetType().FullName))); }
/// <summary> /// Generate code. /// </summary> /// <param name="gen">The specified APGen generation object.</param> public override void Generate(APGen gen) { if (!Enabled) return; CodeNamespace cns = gen.GetCodeNamespace(gen.DefaultNamespace); cns.Imports.Add(new CodeNamespaceImport("Symber.Web.Data")); foreach (APGenEnum em in Enums) { if (em.Enabled) { // Create a enum string enumComment = String.IsNullOrEmpty(em.Comment) ? em.Name : em.Comment; CodeTypeDeclaration enumImp = NewEnum(em.Name, TypeAttributes.Public, enumComment); if (em.IsFlags) enumImp.CustomAttributes.Add(AttrDecl(TypeRef("Flags"))); // Fields int value = 1; foreach (APGenEnumItem item in em.EnumItems) { string comment = String.IsNullOrEmpty(item.Comment) ? item.Name : item.Comment; if (em.IsFlags && item.DefaultValue == null) enumImp.Members.Add(NewEnumItem(item.Name, comment, string.Format("0x{0:x2}", value))); else enumImp.Members.Add(NewEnumItem(item.Name, comment, item.DefaultValue)); value = value * 2; } cns.Types.Add(enumImp); // Create dictionary CodeTypeDeclaration dicImp = NewClass(em.Name + "APEnumDictionary", TypeAttributes.Public, enumComment + " APEnumDictionary"); dicImp.IsPartial = true; CodeMemberField field = NewMemberField("Dictionary", TypeTRef("APEnumDictionary", TypeRef(em.Name)), MemberAttributes.Public | MemberAttributes.Static, null); CodeMethodInvokeExpression create = MethodInvoke(new CodeTypeReferenceExpression(TypeTRef("APEnumDictionary", TypeRef(em.Name))), "Create"); foreach (APGenEnumItem item in em.EnumItems) { string comment = String.IsNullOrEmpty(item.Comment) ? item.Name : item.Comment; CodeMemberField nameField = NewMemberField(item.Name + "Name", TypeRef(typeof(string)), MemberAttributes.Public | MemberAttributes.Const, comment); nameField.InitExpression = Const(item.DictionaryName == "" ? item.Name : item.DictionaryName); dicImp.Members.Add(nameField); create.Parameters.Add(New(new CodeTypeReference("KeyValuePair", TypeRef(em.Name), TypeRef(typeof(string))), PropRef(TypeRefExp(em.Name), item.Name), FieldRef(item.Name + "Name") /*Const(item.DictionaryName)*/)); } field.InitExpression = create; dicImp.Members.Add(field); cns.Types.Add(dicImp); } } }
/// <summary> /// Generate code. /// </summary> /// <param name="gen">The specified APGen generation object.</param> public override void Generate(APGen gen) { if (!Enabled) { return; } CodeNamespace cns = gen.GetCodeNamespace(gen.DefaultNamespace); cns.Imports.Add(new CodeNamespaceImport("Symber.Web.Data")); foreach (APGenEnum em in Enums) { if (em.Enabled) { // Create a enum string enumComment = String.IsNullOrEmpty(em.Comment) ? em.Name : em.Comment; CodeTypeDeclaration enumImp = NewEnum(em.Name, TypeAttributes.Public, enumComment); if (em.IsFlags) { enumImp.CustomAttributes.Add(AttrDecl(TypeRef("Flags"))); } // Fields int value = 1; foreach (APGenEnumItem item in em.EnumItems) { string comment = String.IsNullOrEmpty(item.Comment) ? item.Name : item.Comment; if (em.IsFlags && item.DefaultValue == null) { enumImp.Members.Add(NewEnumItem(item.Name, comment, string.Format("0x{0:x2}", value))); } else { enumImp.Members.Add(NewEnumItem(item.Name, comment, item.DefaultValue)); } value = value * 2; } cns.Types.Add(enumImp); // Create dictionary CodeTypeDeclaration dicImp = NewClass(em.Name + "APEnumDictionary", TypeAttributes.Public, enumComment + " APEnumDictionary"); dicImp.IsPartial = true; CodeMemberField field = NewMemberField("Dictionary", TypeTRef("APEnumDictionary", TypeRef(em.Name)), MemberAttributes.Public | MemberAttributes.Static, null); CodeMethodInvokeExpression create = MethodInvoke(new CodeTypeReferenceExpression(TypeTRef("APEnumDictionary", TypeRef(em.Name))), "Create"); foreach (APGenEnumItem item in em.EnumItems) { string comment = String.IsNullOrEmpty(item.Comment) ? item.Name : item.Comment; CodeMemberField nameField = NewMemberField(item.Name + "Name", TypeRef(typeof(string)), MemberAttributes.Public | MemberAttributes.Const, comment); nameField.InitExpression = Const(item.DictionaryName == "" ? item.Name : item.DictionaryName); dicImp.Members.Add(nameField); create.Parameters.Add(New(new CodeTypeReference("KeyValuePair", TypeRef(em.Name), TypeRef(typeof(string))), PropRef(TypeRefExp(em.Name), item.Name), FieldRef(item.Name + "Name") /*Const(item.DictionaryName)*/)); } field.InitExpression = create; dicImp.Members.Add(field); cns.Types.Add(dicImp); } } }
/// <summary> /// Generate source code and database with the business modes. /// </summary> /// <param name="gen">The specified APGen generation object.</param> public override void Generate(APGen gen) { if (!Enabled) return; InitPrefix(); CodeNamespace cns = gen.GetCodeNamespace(Namespace ?? gen.DefaultNamespace); cns.Imports.Add(new CodeNamespaceImport("System")); cns.Imports.Add(new CodeNamespaceImport("System.Collections")); cns.Imports.Add(new CodeNamespaceImport("System.Collections.Generic")); cns.Imports.Add(new CodeNamespaceImport("System.Data")); cns.Imports.Add(new CodeNamespaceImport("System.ComponentModel.DataAnnotations")); cns.Imports.Add(new CodeNamespaceImport("Symber.Web.Data")); // class APDBDef CreateDatabaseDef(cns); // class APDalDef CodeTypeDeclaration dalDef = CreateDalDef(cns); // class APBplDef CodeTypeDeclaration bplDef = CreateBplDef(cns); foreach (APGenTable table in Tables) { // class a Data CreateData(cns, table, false); // class a Dal CreateDal(dalDef, table, false); // class a Bpl CreateBpl(bplDef, table, false); } foreach (APGenTable view in Views) { // class a Data CreateData(cns, view, true); // class a Dal CreateDal(dalDef, view, true); // class a Bpl CreateBpl(bplDef, view, true); } }