コード例 #1
0
ファイル: Program.cs プロジェクト: bigfirestart/OOP
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Invalid program args");
                return;
            }

            ParsedIniFile parser = null;

            try {
                parser = IniParser.Parse(args[0]);
            }
            catch (ParserException e) {
                Console.WriteLine(e.Message);
                return;
            }

            //reading data
            Console.WriteLine("Section: ");
            var section = Console.ReadLine();

            Console.WriteLine("key: ");
            var key = Console.ReadLine();

            Console.WriteLine("Type: ");
            var type = Console.ReadLine();

            //trying extract
            if (!Enum.GetNames(typeof(AllowedTypes)).Contains(type))
            {
                return;
            }
            try {
                switch (type)
                {
                case "Int":
                    Console.WriteLine(parser.GetInt(section, key));
                    break;

                case "Float":
                    Console.WriteLine(parser.GetFloat(section, key));
                    break;

                default:
                    Console.WriteLine(parser.GetString(section, key));
                    break;
                }
            }
            catch (ParserException e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: DUNNIK/INIParser
        private static void Main(string[] args)
        {
            if (args.Length > 1)
            {
                Console.Error.WriteLine(
                    "Wrong number of parameters!" +
                    "\nUsage: INIParser.exe temp.ini");
                return;
            }

            try
            {
                _inifile = IniParser.Parse(args[0]);
            }
            catch (FileParseExeption)
            {
                Console.Error.WriteLine("File subsystem error!");
                return;
            }
            catch (FileFormatExeption)
            {
                Console.Error.WriteLine("File format error!");
                return;
            }

            Console.Write("Section:");
            var section = Console.ReadLine();

            Console.Write("Key:");
            var key = Console.ReadLine();

            Console.Write("Type:");
            var type = Console.ReadLine();

            WhatType(ref type, out var types);

            try
            {
                switch (types)
                {
                case Types.Double:
                    Console.WriteLine($"Your parameter of type double: {_inifile.GetDouble(section, key)}");
                    break;

                case Types.Int:
                    Console.WriteLine($"Your parameter of type integer: {_inifile.GetInt(section, key)}");
                    break;

                case Types.String:
                    Console.WriteLine($"Your parameter of type string: {_inifile.GetString(section, key)}");
                    break;

                default:
                    throw new TypesExeption("Invalid parameter type!");
                }
            }
            catch (TypesExeption)
            {
                Console.Error.WriteLine("Conversion to this type is not possible!");
            }
            catch (SectionKeyExeption)
            {
                Console.Error.WriteLine("The specified pair SECTION PARAMETER is not in the configuration file!");
            }
            catch (ParseExeption)
            {
                Console.Error.WriteLine("Wrong parametr for parse!");
            }
        }