5 namespace CodeGen.utils
10 public static class Utils
18 public static string Read(
string name)
20 if (File.Exists(name))
22 return File.ReadAllText(name);
25 throw new FileNotFoundException(
"file does not exit");
33 public static void Write(
string path,
string fileContext)
35 File.WriteAllText(path, fileContext);
43 public static string Download(
string url)
45 var webClient =
new WebClient();
46 return webClient.DownloadString(url);
55 public static void ValidateArgs(
string lang,
string file)
59 throw new InvalidDataException(
"specify language (-l) flag");
64 throw new InvalidDataException(
"specify file path (-f) flag");
74 public static string GetFileFormat(
string name)
76 var arr = name.Split(
'.');
77 if (!(arr?.Length > 1))
throw new InvalidDataException(
"invalid input file");
78 if (arr.Last().Any(char.IsLetter))
83 throw new InvalidDataException(
"invalid input file");
91 public static string Title(
string @
string)
93 return string.IsNullOrEmpty(@string)
97 ?
char.ToUpper(@
string[0]) + @string.Substring(1)