コード例 #1
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        private static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            var xml = File.ReadAllText(options.XmlFile);

            var classInfo = new Xml2CSharpConverer().Convert(xml);

            var classInfoWriter = new ClassInfoWriter(classInfo, options.CustomNameSpace);

            if (string.IsNullOrEmpty(options.CSharpFileName))
            {
                classInfoWriter.WriteHeader(Console.Out);
                classInfoWriter.Write(Console.Out);
                classInfoWriter.WriteFooter(Console.Out);
            }

            if (!string.IsNullOrEmpty(options.CSharpFileName))
            {
                using (var sw = new StreamWriter(File.OpenWrite(options.CSharpFileName)))
                {
                    classInfoWriter.WriteHeader(sw);
                    classInfoWriter.Write(sw);
                    classInfoWriter.WriteFooter(sw);
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ststeiger/XmlToCSharp
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options))
                return;

            var xml = File.ReadAllText(options.XmlFile);

            var classInfo = new Xml2CSharpConverer().Convert(xml);

            var classInfoWriter = new ClassInfoWriter(classInfo);
            classInfoWriter.Write(Console.Out);
            classInfoWriter.Write(new StreamWriter(File.OpenWrite(options.CSharpFileName)));
        }
コード例 #3
0
ファイル: When_writing.cs プロジェクト: lanicon/XmlToCSharp
        public When_writing()
        {
            var classInfo = new[]
            {
                new Class
                {
                    Name      = "MyClass",
                    XmlName   = "MyClass",
                    Namespace = "",
                    Fields    = new[]
                    {
                        new Field
                        {
                            Name      = "Age",
                            Type      = "String",
                            XmlType   = XmlType.Element,
                            XmlName   = "Age2",
                            Namespace = "wibble"
                        },
                        new Field
                        {
                            Name    = "Name",
                            Type    = "String",
                            XmlName = "Name",
                            XmlType = XmlType.Attribute
                        },
                    }
                }
            };

            var writer = new ClassInfoWriter(classInfo);

            stringWriter = new InMemoryTextWriter();
            writer.Write(stringWriter);
        }
コード例 #4
0
 public void Then_no_duplicate_classes_are_created(string fileName)
 {
     var classInfo = new Xml2CSharpConverer().Convert(File.ReadAllText(Path.Combine("Specs\\ConvertExamples", fileName)));
     var writer = new ClassInfoWriter(classInfo);
     writer.Write(Console.Out);
     classInfo.Select(c => c.Name).Distinct().Should().HaveCount(classInfo.Count());
 }
コード例 #5
0
        public void Then_no_duplicate_classes_are_created(string fileName)
        {
            var classInfo = new Xml2CSharpConverer().Convert(File.ReadAllText(Path.Combine("Specs\\ConvertExamples", fileName)));
            var writer    = new ClassInfoWriter(classInfo);

            writer.Write(Console.Out);
            classInfo.Select(c => c.Name).Distinct().Should().HaveCount(classInfo.Count());
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            var xml = File.ReadAllText(options.XmlFile);

            var classInfo = new Xml2CSharpConverer().Convert(xml);

            var classInfoWriter = new ClassInfoWriter(classInfo);

            classInfoWriter.Write(Console.Out);
            classInfoWriter.Write(new StreamWriter(File.OpenWrite(options.CSharpFileName)));
        }
コード例 #7
0
ファイル: Home.cs プロジェクト: ststeiger/XmlToCSharp
        public Home()
        {
            Get["/"] = parameters =>
            {
                return View["Index"];
            };

            Post["/"] = parameters =>
            {
                var xml = this.Request.Form.xml;
                var classInfo = new Xml2CSharpConverer().Convert(xml);

                var classInfoWriter = new ClassInfoWriter(classInfo);

                var stringWriter = new StringWriter();
                classInfoWriter.Write(stringWriter);

                return View["result", new ConvertResponse { CSharpCode = stringWriter.ToString() }];
            };
        }
コード例 #8
0
ファイル: Home.cs プロジェクト: johnt84/XmlToCSharp
        public Home()
        {
            Get["/"] = parameters =>
            {
                return(View["Index"]);
            };

            Post["/"] = parameters =>
            {
                var xml       = this.Request.Form.xml;
                var classInfo = new Xml2CSharpConverer().Convert(xml);

                var classInfoWriter = new ClassInfoWriter(classInfo);

                var stringWriter = new StringWriter();
                classInfoWriter.Write(stringWriter);

                return(View["result", new ConvertResponse {
                                XmlInput = xml, CSharpCode = stringWriter.ToString()
                            }]);
            };
        }
コード例 #9
0
        public Home()
        {
            Get["/"] = parameters =>
            {
                return(View["Index"]);
            };

            Post["/"] = parameters =>
            {
                var xml       = this.Request.Form.xml;
                var classInfo = new Xml2CSharpConverer().Convert(xml);

                var classInfoWriter = new ClassInfoWriter(classInfo);

                var stringWriter = new StringWriter();
                classInfoWriter.Write(stringWriter);
                File.WriteAllText(@"E:\_MIS_Moalemi\final.cs", stringWriter.ToString());
                return(View["result", new ConvertResponse {
                                CSharpCode = stringWriter.ToString()
                            }]);
            };
        }
コード例 #10
0
ファイル: When_writing.cs プロジェクト: ststeiger/XmlToCSharp
        public When_writing()
        {
            var classInfo = new[]
                {
                    new Class
                    {
                        Name = "MyClass",
                        XmlName = "MyClass",
                        Namespace = "",
                        Fields = new[]
                        {
                            new Field
                            {
                                Name = "Age",
                                Type = "String",
                                XmlType = XmlType.Element,
                                XmlName = "Age2",
                                Namespace = "wibble"
                            },
                            new Field
                            {
                                Name = "Name",
                                Type = "String",
                                XmlName = "Name",
                                XmlType = XmlType.Attribute
                            },
                        }
                    }

            };

            var writer = new ClassInfoWriter(classInfo);
            stringWriter = new InMemoryTextWriter();
            writer.Write(stringWriter);
        }