コード例 #1
0
        public static void handleFileConversion(string[] args)
        {
            if (args.Length < 9)
            {
                Console.WriteLine("Not enough arguments");
                return;
            }

            if (args[1] == "--from" && args[3] == "--to" && args[5] == "--source" && args[7] == "--target")
            {
                if (args[2] == "json" && args[4] == "xml")
                {
                    JsonToXmlConverter converter = new JsonToXmlConverter();
                    converter.convert(args[6], args[8]);
                }
                else if (args[2] == "xml" && args[4] == "json")
                {
                    XmlToJsonConverter converter = new XmlToJsonConverter();
                    converter.convert(args[6], args[8]);
                }
                else
                {
                    Console.WriteLine("Invalid conversion formats");
                }
            }
            else
            {
                Console.WriteLine("Wrong arguments fromat");
            }
        }
コード例 #2
0
        public static void handleStringConversion(string[] args)
        {
            if (args.Length < 6)
            {
                Console.WriteLine("Not enough arguments");
                return;
            }

            if (args[1] == "--from" && args[3] == "--to")
            {
                if (args[2] == "json" && args[4] == "xml")
                {
                    JsonToXmlConverter converter = new JsonToXmlConverter();
                    Console.WriteLine(converter.convert(args[5]));
                }
                else if (args[2] == "xml" && args[4] == "json")
                {
                    XmlToJsonConverter converter = new XmlToJsonConverter();
                    Console.WriteLine(converter.convert(args[5]));
                }
                else
                {
                    Console.WriteLine("Invalid conversion formats");
                }
            }
            else
            {
                Console.WriteLine("Cannot identify 'from' and 'to' parameters");
            }
        }