コード例 #1
0
ファイル: XsdWrapperDemo.cs プロジェクト: tmauldin/mb-unit
        public static void GUnit()
        {
            // XSD wrapper demo
            XsdWrapperGenerator xsg = new XsdWrapperGenerator("GUnit.Core.Reports.Serialization");

            foreach (Type t in Assembly.GetExecutingAssembly().GetExportedTypes())
            {
                if (t.Namespace != "GUnit.Core.Reports.Xsd")
                {
                    continue;
                }
                xsg.Add(t);
            }
            xsg.Generate();

            // getting generator
            CodeGenerator gen = new CodeGenerator();

            gen.GenerateCode("..\\..", xsg.Ns);
        }
コード例 #2
0
ファイル: XsdWrapperDemo.cs プロジェクト: tmauldin/mb-unit
        public static void NCover()
        {
            // XSD wrapper demo
            XsdWrapperGenerator xsg = new XsdWrapperGenerator("NCover");

            foreach (Type t in Assembly.GetExecutingAssembly().GetExportedTypes())
            {
                if (t.Namespace != "NCover")
                {
                    continue;
                }
                xsg.Add(t);
            }
//			xsg.Ns.Conformer.AddWord("seqpnt");
            xsg.Generate();

            // getting generator
            CodeGenerator gen = new CodeGenerator();

            gen.GenerateCode("..\\..", xsg.Ns);
        }
コード例 #3
0
        private void Generate()
        {
            // check data...
            SetStatusBar("Checking data");
            Application.DoEvents();
            this.config.CheckData();

            // Build Xsd path & file name and take care of instances where
            // '\' is missing from path and where path is empty.
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(this.config.XsdExePath.TrimEnd('\\'));
            if (sb.Length > 0)
            {
                sb.Append(@"\");
            }
            sb.Append("xsd.exe");

            // call xsd.exe
            ProcessStartInfo info = new ProcessStartInfo(sb.ToString());

            Application.DoEvents();
            info.UseShellExecute = false;
            info.Arguments       = String.Format(
                "\"{0}\" /c /n:{1}",
                this.config.XsdFile,
                this.config.OutputNamespace
                );

            SetStatusBar("Launching Xsd.exe");
            Application.DoEvents();
            Process process = Process.Start(info);

            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                throw new Exception("Xsd.exe failed");
            }

            // load and compile generated file
            string[] namePieces = this.config.XsdFile.Split('.', '/', '\\');
            string   fileName   = (namePieces[namePieces.Length - 2] + ".cs").ToLower();

            if (!File.Exists(fileName))
            {
                throw new Exception("File " + fileName + " does not exist");
            }

            // compile
            CSharpCodeProvider provider = new CSharpCodeProvider();

            // Obtain an ICodeGenerator from a CodeDomProvider class.
            ICodeCompiler      comp    = provider.CreateCompiler();
            CompilerParameters options = new CompilerParameters();

            options.GenerateInMemory        = true;
            options.IncludeDebugInformation = true;
            options.ReferencedAssemblies.Add("System.dll");
            options.ReferencedAssemblies.Add("System.Xml.dll");

            SetStatusBar("Compiling result");
            CompilerResults result = comp.CompileAssemblyFromFile(options, fileName);

            if (result.Errors.HasErrors)
            {
                StringWriter sw = new StringWriter();
                foreach (CompilerError error in result.Errors)
                {
                    sw.WriteLine(error.ToString());
                }
                throw new Exception(sw.ToString());
            }

            SetStatusBar("Recfactoring output");
            XsdWrapperGenerator xsg = new XsdWrapperGenerator(this.config.OutputNamespace);

            xsg.Conformer.Camelize   = this.config.AutoCamelize;
            xsg.Conformer.Capitalize = this.config.AutoCapitalize;
            foreach (Type t in result.CompiledAssembly.GetExportedTypes())
            {
                xsg.Add(t);
            }
            xsg.Generate();

            // getting generator
            Refly.CodeDom.CodeGenerator gen = new Refly.CodeDom.CodeGenerator();

            SetStatusBar("Generating refactored classes");
            gen.CreateFolders = this.config.CreateNamespaceFolders;
            gen.GenerateCode(this.config.OutputPath, xsg.Ns);
            SetStatusBar("Generation finished successfully");
        }