Beispiel #1
0
 private void GenerateHelper()
 {
     using (GenParamsForm gpf = new GenParamsForm())
     {
         gpf.Namespace = _rootCategory.Name;
         if (gpf.ShowDialog(this) == DialogResult.OK)
         {
             CodeCompileUnit ccu = HelperGenerator.Generate(_rootCategory,
                                                            gpf.Namespace, gpf.IsInternal);
             CSharpCodeProvider   cscp = new CSharpCodeProvider();
             CodeGeneratorOptions cgo  = new CodeGeneratorOptions();
             cgo.BracingStyle = "C";
             using (StreamWriter sw = new StreamWriter(
                        Path.Combine(_directory, _rootCategory.TreeName + ".cs")))
                 cscp.GenerateCodeFromCompileUnit(ccu, sw, cgo);
             if (gpf.ShowResult)
             {
                 using (ShowResultForm srf = new ShowResultForm())
                     using (StringWriter strW = new StringWriter())
                     {
                         cscp.GenerateCodeFromCompileUnit(ccu, strW, cgo);
                         srf.Result = strW.ToString();
                         srf.ShowDialog(this);
                     }
             }
         }
     }
 }
Beispiel #2
0
        private void CreateILRuntimeHelper()
        {
            Print($"==================Begin create helper:=====================");

            _helpGenerator.LoadData(new Tuple <Dictionary <string, TypeDefinition>, Dictionary <string, TypeDefinition>, Dictionary <string, TypeReference> >(_adaptorDic, _delegateCovDic, _delegateRegDic));
            var helperStr = _helpGenerator.Generate();

            using (var fs2 = File.Create(_outputPath + "helper.cs"))
            {
                var sw = new StreamWriter(fs2);
                sw.Write(helperStr);
                sw.Flush();
            }

            Print($"==============End create helper:===================");
        }
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                using (var mf = new MainForm())
                {
                    var cont = new RootAppContainer(mf);
                    cont.Add(mf);
                    Application.Run(mf);
                }
            }
            else
            {
                if (args.Length != 4)
                {
                    Console.WriteLine(msgBadArgCount);
                    return;
                }
                if (!File.Exists(args[0]))
                {
                    Console.WriteLine(msgResourceFileNotFound);
                    return;
                }
                if (!Directory.Exists(args[3]))
                {
                    Console.WriteLine(msgOutputDirNotFound);
                    return;
                }

                Console.Write("Generate resource helper ... ");
                CultureInfo[] loadedCultures;
                DateTime      lmt;
                var           rc = Loader.Load(args[0], out loadedCultures,
                                               out lmt);
                var outFile = Path.Combine(args[3], rc.TreeName + ".cs");
                Console.WriteLine(outFile);
                if (File.Exists(outFile) && lmt <= File.GetLastWriteTime(outFile))
                {
                    Console.WriteLine(msgFileUpToDate);
                    return;
                }
                if (File.Exists(outFile) && (File.GetAttributes(outFile) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    Console.WriteLine(msgReadOnlyError);
                    return;
                }

                bool isInternal;
                if (args[2] == "public")
                {
                    isInternal = false;
                }
                else if (args[2] == "internal")
                {
                    isInternal = true;
                }
                else
                {
                    throw new ArgumentException("Invalid class modifier argument");
                }

                var ccu = HelperGenerator.Generate(rc,
                                                   args[1], isInternal);
                var cscp = new CSharpCodeProvider();
                var cgo  = new CodeGeneratorOptions {
                    BracingStyle = "C"
                };
                using (var sw = new StreamWriter(
                           Path.Combine(args[3], rc.TreeName + ".cs")))
                    cscp.GenerateCodeFromCompileUnit(ccu, sw, cgo);
            }
        }