public static void Main(string[] args) { if (args.Length < 1 && args.Length > 4) { Console.Error.WriteLine("Invalid number of args"); return; } ParsedIniFile parser = null; try { parser = IniParser.Parse(args[0]); } catch (ParserException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.InnerException.Message); Console.Error.WriteLine(e.StackTrace); return; } var section = args[1]; var key = args[2]; var type = args[3]; if (!Enum.GetNames(typeof(AvailableTypes)).Any(x => x.ToLower() == type.ToLower())) { Console.Error.WriteLine("Incorrect type."); return; } try { switch (type.ToLower()) { case "int": Console.WriteLine(parser.TryGetInt(section, key)); break; case "float": Console.WriteLine(parser.TryGetFloat(section, key)); break; case "string": Console.WriteLine(parser.TryGetString(section, key)); break; default: Console.Error.WriteLine("Incorrect type."); break; } } catch (FileNotFoundException) { Console.Error.WriteLine("File not found"); } catch (ParserException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.InnerException.Message); Console.Error.WriteLine(e.StackTrace); } }
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); } }
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!"); } }