static void generateApp(ProjectItemGroupElement pige, IXamlFileGenerationData ixfgd) { #if true generateNode(pige, ixfgd.xamlName, "Generator", "ApplicationDefinition"); #else IDictionary<string, string> tmp = new Dictionary<string, string>(); tmp.Add("Generator", "MSBuild:Compile"); tmp.Add("SubType", "Generator"); pige.AddItem("ApplicationDefinition", ixfgd.xamlName, tmp); Debug.Print("Adding: " + ixfgd.xamlName); #endif generateDependentCompile(pige, ixfgd.codeBehindName, ixfgd.xamlName); }
/// <summary>do it.</summary> /// <param name="ixfgd"></param> /// <param name="opts"></param> internal static void generateFile(IXamlFileGenerationData ixfgd, PGOptions opts) { StringBuilder sb; string fname, ename, ns, modelName, ext; if (ixfgd == null) throw new ArgumentNullException("ixfgd", "generation-object is null!"); if (string.IsNullOrEmpty(ename = ixfgd.elementName)) throw new ArgumentNullException("ename", "element-name is null!"); if (string.IsNullOrEmpty(fname = ixfgd.fileName)) if (string.IsNullOrEmpty(fname)) throw new ArgumentNullException("fname", "file-name is null!"); if (ixfgd.generationType == GenFileType.View) ixfgd.xamlName = Path.Combine("Source\\Views\\", fname + ".xaml"); else ixfgd.xamlName = fname + ".xaml"; ns = ixfgd.nameSpace; sb = new StringBuilder(); if (DefaultProjectGenerator.dontOverwriteFile(ixfgd.xamlName)) return; using (StringWriter sw = new StringWriter(sb)) { using (XmlWriter xw = XmlWriter.Create(sw, settings)) { xw.WriteStartElement(ename, NS_DEFAULT); xw.WriteAttributeString("xmlns", "x", null, NS_X); xw.WriteAttributeString("xmlns", "d", null, NS_BLEND); if (!string.IsNullOrEmpty(ns)) xw.WriteAttributeString("xmlns", "local", null, "clr-namespace:" + ns); ixfgd.populateElementAttributes(xw); ixfgd.populateElement(xw); xw.WriteEndDocument(); } } if (showFileContent) Debug.Print(sb.ToString()); createDirIfNeeded(ixfgd.xamlName); File.WriteAllText(ixfgd.xamlName, sb.ToString()); ext = opts.provider.FileExtension; modelName = fname + "ViewModel"; if (ixfgd.generationType == GenFileType.View) { ixfgd.codeBehindName = Path.Combine("Source\\Views", fname + ".xaml." + ext); ixfgd.viewModelName = Path.Combine("Source\\Models\\", modelName + "." + ext); } else { ixfgd.codeBehindName = fname + ".xaml." + ext; ixfgd.viewModelName = modelName + "." + ext; } createMainFile(ixfgd.codeBehindName, ns, fname, ename, modelName, ixfgd.generateViewModel, ixfgd, opts); if (ixfgd.generateViewModel) createModelfile(ixfgd.viewModelName, ns, modelName, ixfgd, opts); }
static void generatePageAndModel(ProjectItemGroupElement pige, IXamlFileGenerationData hdp) { generatePage(pige, hdp); generateCompile(pige, hdp.viewModelName); }
static void generatePage(ProjectItemGroupElement pige, IXamlFileGenerationData ixfgd) { // string genType = "Designer"; // string itemType = "Page"; generateNode(pige, ixfgd.xamlName, "Designer", "Page"); generateDependentCompile(pige, ixfgd.codeBehindName, ixfgd.xamlName); }
static void createModelfile(string outModelName, string nameSpace, string modelName, IXamlFileGenerationData ixfgd, PGOptions opts) { CodeCompileUnit ccu = null; CodeNamespace ns0, ns; CodeTypeDeclaration ctd; CodeConstructor cc; CodeMemberEvent cme0; CodeMemberMethod cmm0, cmm3; CodeEventReferenceExpression cere; ccu = new CodeCompileUnit(); ccu.Namespaces.Add(ns = ns0 = new CodeNamespace()); if (!string.IsNullOrEmpty(nameSpace)) ccu.Namespaces.Add(ns = new CodeNamespace(nameSpace)); ns0.Imports.Add(new CodeNamespaceImport("System.ComponentModel")); ns0.Imports.Add(new CodeNamespaceImport("System.Reflection")); ns.Types.Add(ctd = new CodeTypeDeclaration(modelName)); if (opts.provider.Supports(GeneratorSupport.PartialTypes)) ctd.IsPartial = true; ctd.BaseTypes.Add("INotifyPropertyChanged"); cere = new CodeEventReferenceExpression(ceThis, "PropertyChanged"); ctd.Members.AddRange(new CodeTypeMember[] { cme0=createEvent(cere), cc=new CodeConstructor(), cmm0=createMethod1("firePropertyChanged",cere,new CodeArgumentReferenceExpression ("propertyName")), cmm3=createMethod2("firePropertyChanged",cere,new CodeArgumentReferenceExpression ("mb")) }); ; cc.Attributes = MemberAttributes.Public; ixfgd.generateModelCode(ns, ctd); outputFile(ccu, ns, outModelName, opts); }
static void createMainFile(string outCSName, string nameSpace, string fname, string ename, string modelName, bool generateViewModel, IXamlFileGenerationData ixfgd, PGOptions opts) { CodeCompileUnit ccu = null; CodeNamespace ns0, ns; CodeTypeDeclaration ctd; CodeConstructor cc = null; CodeMemberField f; CodeFieldReferenceExpression fr = null; ccu = new CodeCompileUnit(); ccu.Namespaces.Add(ns = ns0 = new CodeNamespace()); if (!string.IsNullOrEmpty(nameSpace)) ccu.Namespaces.Add(ns = new CodeNamespace(nameSpace)); ixfgd.addImports(ns0); ns.Types.Add(ctd = new CodeTypeDeclaration(fname)); if (opts.provider.Supports(GeneratorSupport.PartialTypes)) ctd.IsPartial = true; ctd.BaseTypes.Add(ename); if (generateViewModel) { fr = new CodeFieldReferenceExpression(null, "_vm"); ctd.Members.Add(f = new CodeMemberField(modelName, fr.FieldName)); f.Attributes = 0; ctd.Members.Add(cc = new CodeConstructor()); cc.Attributes = MemberAttributes.Public; cc.Statements.Add( new CodeAssignStatement( new CodePropertyReferenceExpression(ceThis, "DataContext"), new CodeBinaryOperatorExpression(fr, CodeBinaryOperatorType.Assign, new CodeObjectCreateExpression(modelName)))); cc.Statements.Add( new CodeExpressionStatement( new CodeMethodInvokeExpression(null, "InitializeComponent", new CodeExpression[0]))); } ixfgd.generateCode(ns, ctd, cc); outputFile(ccu, ns, outCSName, opts); }