static void Main()

in CSharp/Tools/RView/Program.cs [58:174]


        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Usage();
            }
            string path = null;
            string locale = null;
            string assemblyPath = null;
            string methodPath = null;
            for (var i = 0; i < args.Length; ++i)
            {
                var arg = args[i];
                if (arg.StartsWith("-"))
                {
                    switch (arg)
                    {
                        case "-c":
                            if (++i < args.Length)
                            {
                                locale = args[i];
                            }
                            break;
                        case "-g":
                            if (++i < args.Length)
                            {
                                assemblyPath = Path.GetFullPath(args[i]);
                            }
                            if (++i < args.Length)
                            {
                                methodPath = args[i];
                            }
                            break;
                        default:
                            Usage();
                            break;
                    }
                }
                else
                {
                    path = arg;
                }
            }

            if (assemblyPath != null)
            {
                var assembly = Assembly.LoadFrom(assemblyPath);
                var methodParts = methodPath.Split('.');
                var methodName = methodParts.Last();
                var className = string.Join(".", methodParts.Take(methodParts.Count() - 1));
                var classType = assembly.GetType(className);
                var method = classType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
                var methodArgs = new object[method.GetParameters().Length];
                var form = method.Invoke(null, methodArgs);
                var formPath = className + ".resx";
                using (var stream = new FileStream(formPath, FileMode.Create))
                using (var writer = new ResXResourceWriter(stream))
                {
                    form.GetType().InvokeMember("SaveResources",
                        BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                        null, form, new object[] { writer });
                }
                Console.WriteLine($"Generated {formPath} by calling {methodPath} in {assemblyPath}.");
            }
            else
            {
                var isResX = Path.GetExtension(path) == ".resx";
                IResourceWriter writer = null;
                FileStream outStream = null;
                if (locale != null)
                {
                    var outPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "-" + locale + Path.GetExtension(path));
                    Console.Write($"Copying to {outPath}");
                    Console.WriteLine();
                    outStream = new FileStream(outPath, FileMode.Create);
                    writer = isResX ? (IResourceWriter)new ResXResourceWriter(outStream) : (IResourceWriter)new ResourceWriter(outStream);
                }
                using (var stream = new FileStream(path, FileMode.Open))
                using (var reader = isResX ? (IResourceReader)new ResXResourceReader(stream) : (IResourceReader)new ResourceReader(stream))
                using (outStream)
                using (writer)
                {
                    int values = 0;
                    int lists = 0;
                    int templates = 0;
                    foreach (DictionaryEntry entry in reader)
                    {
                        var fullKey = (string)entry.Key;
                        var value = (string)entry.Value;
                        var typeAndKey = fullKey.Split(SEPERATOR);
                        var type = typeAndKey.Last();
                        if (writer == null)
                        {
                            Console.WriteLine($"{fullKey}: {value}");
                        }
                        else
                        {
                            if (type == "LIST" || type == "TEMPLATE")
                            {
                                writer.AddResource(fullKey, MakeList(from elt in SplitList(value) select "<" + elt + ">"));
                            }
                            else
                            {
                                writer.AddResource(fullKey, "<" + value + ">");
                            }
                        }
                        switch (type)
                        {
                            case "VALUE": ++values; break;
                            case "LIST": ++lists; break;
                            case "TEMPLATE": ++templates; break;
                        }
                    }
                    Console.WriteLine($"Found {values} values, {lists} lists and {templates} templates");
                }
            }
        }