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); }
protected void Save(CsFile file, CsClass cl, params string[] subDirs) { var a = new List <string> { BasePath.FullName }; a.AddRange(subDirs); a.Add(cl.GetShortName()); var fileName = Path.Combine(a.ToArray()); file.SaveIfDifferent(fileName); }
protected CsClass Get(string name, out CsFile file) { var info = CsFilesManager.Instance.GetFileInfo(name, _nameSpace); file = info.File; if (!info.IsEmbedded) { PrepareFile(file); } var ns = file.GetOrCreateNamespace(_nameSpace); var t = ns.GetOrCreateClass(name); t.IsPartial = true; if (!info.IsEmbedded) { var filename = Path.Combine(_output, name + ".auto.cs"); file.SaveIfDifferent(filename); } return(t); }
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); } } }