예제 #1
0
 protected virtual void PrepareFile(CsFile file)
 {
     if (file.Namespaces.Any())
     {
         return;
     }
     file.AddImportNamespace("System");
     file.AddImportNamespace("System.Globalization");
     file.AddImportNamespace("System.Collections.Generic");
     file.AddImportNamespace("JetBrains.Annotations");
 }
예제 #2
0
        protected static CsFile CreateFile()
        {
            var file = new CsFile();

            file.AddImportNamespace("System");
            return(file);
        }
        public static void Run(string basePath)
        {
            var gen = new KeysGenerator();
            var a   = typeof(KeysGeneratorRunner).Assembly;

            void AddString(string n, string p = "Value")
            {
                gen.Add(new KeysGeneratorDef(n, a, WrappedTypes.String, p));
            }

            AddString(nameof(XValueTypeName), nameof(XValueTypeName.ValueTypeName));
            AddString(nameof(XUnitTypeName), nameof(XUnitTypeName.TypeName));
            AddString(nameof(XUnitContainerTypeName), nameof(XUnitContainerTypeName.TypeName));

            var file = new CsFile();

            file.AddImportNamespace("System");
            IAutoCodeGeneratorContext ctx =
                new AutoCodeGenerator.SimpleAutoCodeGeneratorContext(file,
                                                                     type =>
            {
                var c       = file.GetOrCreateClass(type);
                c.IsPartial = true;
                return(c);
            });

            gen.AssemblyStart(a, ctx);
            gen.AssemblyEnd(a, ctx);

            var filename = Path.Combine(basePath, "Keys.auto.cs");

            file.SaveIfDifferent(filename);
        }
        public Result GetFileInfo(string name, string nameSpace)
        {
            var units  = name.EndsWith("Units") || name.EndsWith("Unit");
            var csFile = new CsFile();

            csFile.AddImportNamespace("System");
            csFile.AddImportNamespace("System.Collections.Generic");
            if (units)
            {
                if (name.EndsWith("Units"))
                {
                    name = name.Substring(0, name.Length - 1);
                }
            }
            else
            {
                name = CutEnd(name, "JsonConverter");
                name = CutEnd(name, "Extensions");
                csFile.AddImportNamespace("System.Globalization");
                csFile.AddImportNamespace("Newtonsoft.Json");
            }

            var key = nameSpace + "--" + name;

            if (_cache.TryGetValue(key, out var r))
            {
                return(r);
            }

            var fileName = Path.Combine(GetDir(units));

            if (_subFolders.TryGetValue(name, out var sf))
            {
                fileName = Path.Combine(fileName, sf);
            }

            fileName = Path.Combine(fileName, name + ".cs");
            return(_cache[key] = new Result(true, csFile, fileName));
        }
예제 #5
0
        public void AssemblyStart(Assembly assembly, IAutoCodeGeneratorContext context)
        {
            var projectDir = _assemblyBaseDirectoryProvider.GetBaseDirectory(assembly);

            foreach (var item in ItemsToCreate)
            {
                if (item.TargetAssembly != assembly)
                {
                    continue;
                }
                var csFile = new CsFile();
                foreach (var ns in AllGenerators.GetFileImportNamespaces())
                {
                    csFile.AddImportNamespace(ns);
                }
                var privContext = new MyWrappedContext(csFile);
                SingleTaskEnumsGenerator.CreateCode(privContext, item);
                var fileToSave = item.GetFileName(projectDir);
                if (csFile.SaveIfDifferent(fileToSave.FullName))
                {
                    context.FileSaved(fileToSave);
                }
            }
        }
예제 #6
0
 protected virtual void ProcessFile(CsFile file)
 {
     file.AddImportNamespace("System");
 }
 protected override void PrepareFile(CsFile file)
 {
     base.PrepareFile(file);
     file.AddImportNamespace("System.Runtime.CompilerServices");
 }
예제 #8
0
 protected override void PrepareFile(CsFile file)
 {
     base.PrepareFile(file);
     file.AddImportNamespace("Newtonsoft.Json");
 }
예제 #9
0
 protected override void PrepareFile(CsFile file)
 {
     base.PrepareFile(file);
     file.AddImportNamespace("System.Linq");
     file.AddImportNamespace("System.Collections.Generic");
 }