public void ShouldReplaceConstructorNameWithProgram() { var code = "class MyClass { public MyClass() {} }"; var syntaxTree = roslynFixture.CreateSyntaxTree(code); var classTree = roslynFixture.FindFirstClassDeclaration(syntaxTree); var script = scriptGenerator.Generate(new AnalyzedClass { ClassTree = classTree, ClassShortName = "MyClass" }, new HashSet <AnalyzedClass>()); StringAssert.Contains(script, "public Program() {}"); }
public static void Generate(string assemblyPath, string targetDirectory, Action <string, string> logError, Func <string, string> promotionPathFinder) { var writer = new ScriptGenerator(assemblyPath, targetDirectory, promotionFinder: promotionPathFinder, logError: logError); writer.Generate(); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, ClassName = $"{GeneratorWindow.SceneNameList[CurrentSceneNameIndex]}{LayerType.ToString()}", SceneName = GeneratorWindow.SceneNameList[CurrentSceneNameIndex], Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); GeneratorWindow.GetAdditionalStructureExtensionDelegateList(LayerType)?.ToList().ForEach(x => x(parameter)); if (parameter.UsingList.IsEmpty()) { parameter.UsingList.Add("CAFU.Core.Presentation.Presenter"); parameter.ImplementsInterfaceList.Add("IPresenter"); } if (HasFactory) { parameter.UsingList.Add("CAFU.Core.Presentation.Presenter"); } var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); if (HasFactory) { generator.AddPartial(Factory.StructureName, GeneratorWindow.GetPartialStructure(Factory.StructureName).Render(parameter)); } generator.Generate(CreateOutputPath(parameter)); }
public ActionResult Index(ApplicationModel model) { var generator = new ScriptGenerator(HttpContext.Server.MapPath(Configuration.TemplatePath), Configuration.ScriptsStoragePath); generator.Generate(model); return(RedirectToAction("Index")); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, InterfaceName = $"I{ClassName}", ClassName = ClassName, IsSingleton = IsSingleton, Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); GeneratorWindow.GetAdditionalStructureExtensionDelegateList(LayerType)?.ToList().ForEach(x => x(parameter)); parameter.UsingList.Add("CAFU.Core.Data.DataStore"); parameter.ImplementsInterfaceList.Add(parameter.InterfaceName); var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); if (HasFactory) { generator.AddPartial(Factory.StructureName, GeneratorWindow.GetPartialStructure(Factory.StructureName).Render(parameter)); } generator.Generate(CreateOutputPath(parameter)); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, ClassName = ClassName, SceneName = GeneratorWindow.SceneNameList[CurrentSceneNameIndex], Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); GeneratorWindow.GetAdditionalStructureExtensionDelegateList(LayerType)?.ToList().ForEach(x => x(parameter)); if (parameter.UsingList.IsEmpty()) { parameter.UsingList.Add("UnityEngine"); parameter.UsingList.Add("CAFU.Core.Presentation.View"); parameter.ImplementsInterfaceList.Add("IView"); parameter.BaseClassName = "MonoBehaviour"; } var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.AddPartial(StartMethod.StructureName, GeneratorWindow.GetPartialStructure(StartMethod.StructureName).Render(parameter)); generator.Generate(CreateOutputPath(parameter)); }
private void OnGUIPropertiesMapping() { GUILayout.FlexibleSpace(); GUILayout.Label("Select question type for each property: "); GUILayout.FlexibleSpace(); foreach (var property in this._propertyQuestions.Keys.ToList()) { EditorGUILayout.BeginHorizontal(); string type = property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) ? $@"{property.PropertyType.GetGenericArguments()[0].Name}?" : property.PropertyType.Name; GUILayout.Label($@"{type}", GUILayout.Width(90)); GUILayout.Label($@"{property.Name}", GUILayout.Width(170)); this._propertyQuestions[property] = (QuestionType)EditorGUILayout.EnumPopup(this._propertyQuestions[property]); EditorGUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (GUILayout.Button("back")) { this._currentWindow = Window.ContextClassSelection; } if (GUILayout.Button("Generate survey form")) { var sceneGenerator = new SurveyFormSceneCreator(this._propertyQuestions); sceneGenerator.Create(); var scriptGenerator = new ScriptGenerator(this._selectedContextType, this._selectedEntityType, this._propertyQuestions); var className = $"{this._selectedEntityType.Name}Script"; string script = scriptGenerator.Generate(className); string path = $@"{Application.dataPath}\Model\{className}.cs"; File.WriteAllText(path, script); AssetDatabase.Refresh(); GameObject placeHolder = new GameObject("Scripts"); this.Close(); EditorUtility.DisplayDialog("Information", $"Add {className} script to Scripts GameObject", "Ok"); } GUILayout.EndHorizontal(); GUILayout.Label(string.Empty); }
private async Task GenerateObjectScript(string database, DatabaseObject dbObj, ScriptAction scriptAction) { DbInterpreter dbInterpreter = this.GetDbInterpreter(database, false); ScriptGenerator scriptGenerator = new ScriptGenerator(dbInterpreter); string script = await scriptGenerator.Generate(dbObj, scriptAction); this.ShowContent(new DatabaseObjectDisplayInfo() { Name = dbObj.Name, DatabaseType = this.databaseType, DatabaseObject = dbObj, Content = script, ConnectionInfo = dbInterpreter.ConnectionInfo }); }
public void GeneratedVersionedEntityDoesntNeedUpdate() { var databaseMigrator = new DatabaseMigrator(); var configuration = new VersionedConfiguration(); var answerProvider = new Mock <IAnswerProvider>(); databaseMigrator.Execute(configuration, connectionString, "System.Data.SqlClient", Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <KeyValuePair <string, string> >(), answerProvider.Object); var scriptGenerator = new ScriptGenerator(); var script = scriptGenerator.Generate(configuration, connectionString, "System.Data.SqlClient", Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <KeyValuePair <string, string> >(), answerProvider.Object); this.output.WriteLine(script); Assert.True(string.IsNullOrWhiteSpace(script)); }
public void SerializeDeserialize_Script() { var script = ScriptGenerator.Generate(1); string xml = XmlSerialize <Script <TestGlobals> >(script); var deserialized = XmlDeserialize <Script <TestGlobals> >(xml); Assert.IsNotNull(deserialized, "Deserialized object was null"); int hash1 = script.GetHashCode(); int hash2 = deserialized.GetHashCode(); Assert.AreEqual(hash1, hash2, "Hash of original object differs from deserialized object"); }
private static void ExecuteScript(CommandOption assemblyPath, CommandOption configurationType, CommandOption connectionString, CommandOption provider, CommandOption tablesToIgnore, CommandOption indexesToIgnore, CommandOption extraPluralizationWords) { var scriptGenerator = new ScriptGenerator(); var result = scriptGenerator.Generate( AssemblyContext.LoadType <IConfiguration>(assemblyPath.Value(), configurationType.Value()), connectionString.Value(), provider.HasValue() ? provider.Value() : "System.Data.SqlClient", tablesToIgnore.Values, indexesToIgnore.Values, extraPluralizationWords.GetExtraPluralizationWords(), new ConsoleAnswerProvider()); Console.Write(result); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, ClassName = "MusicName", Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.Generate(CreateOutputPath(parameter)); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, InterfaceName = $"I{ClassName}", ClassName = ClassName, Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); GeneratorWindow.GetAdditionalStructureExtensionDelegateList(LayerType)?.ToList().ForEach(x => x(parameter)); var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.Generate(CreateOutputPath(parameter)); }
public static Task Run( CommandArgument assemblyPath, CommandOption outputPath, CommandOption <bool> overwriteOption, CommandOption <bool> cleanOption, CommandOption <DialectTypes> dialectOption, CancellationToken cancellationToken = default) { var output = outputPath.HasValue() ? outputPath.Value() : Directory.GetCurrentDirectory(); var writer = new ScriptGenerator(assemblyPath.Value, output, cleanOption.ParsedValue, overwriteOption.ParsedValue, dialectOption.ParsedValues.ToBuildSqlDialects()); writer.Generate(); Console.WriteLine($"Script for {assemblyPath.Value} was generated at {output}."); return(Task.CompletedTask); }
static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Two parameters expected."); Console.WriteLine("SQLScriptCreator inputfile.xml outputdir"); return(-1); } string fileName = args[0]; string outputDir = args[1]; if (!File.Exists(fileName)) { Console.WriteLine("Input file not found."); return(-1); } if (!Directory.Exists(outputDir)) { Console.WriteLine("Output directory not found."); return(-1); } try { DDLFileParser parser = new DDLFileParser(fileName); List <IStatement> statements = parser.Parse(); ScriptGenerator generator = new ScriptGenerator(statements, outputDir); generator.Generate(); } catch (Exception e) { Console.WriteLine(e.Message); return(-1); } return(0); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, ClassName = GeneratorWindow.SceneNameList[CurrentSceneNameIndex], SceneName = GeneratorWindow.SceneNameList[CurrentSceneNameIndex], Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); parameter.UsingList.Add("System"); parameter.UsingList.Add("CAFU.Timeline.Data.Entity"); parameter.UsingList.Add($"TimelineName = {this.CreateNamespacePrefix()}Application.Enumerate.TimelineName.{parameter.SceneName}"); parameter.BaseClassName = "TimelineEntity<TimelineName>"; var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.Generate(CreateOutputPath(parameter)); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType, LayerType = LayerType, ClassName = "MusicEntity", Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); parameter.UsingList.Add("System"); parameter.UsingList.Add("CAFU.Generics.Data.Entity"); parameter.UsingList.Add("CAFU.Music.Data.Entity"); parameter.UsingList.Add($"{this.CreateNamespacePrefix()}Application.Enumerate"); parameter.UsingList.Add("UnityEngine"); parameter.BaseClassName = "ScriptableObjectGenericEntity"; parameter.ImplementsInterfaceList.Add("IMusicEntity<MusicName>"); var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.Generate(CreateOutputPath(parameter)); }
public override void Generate(bool overwrite) { var parameter = new Parameter() { ParentLayerType = ParentLayerType.Presentation, LayerType = LayerType.View, ClassName = "Controller", SceneName = GeneratorWindow.SceneNameList[CurrentSceneNameIndex], Overwrite = overwrite, }; parameter.Namespace = CreateNamespace(parameter); GeneratorWindow.GetAdditionalStructureExtensionDelegateList(LayerType)?.ToList().ForEach(x => x(parameter)); parameter.UsingList.Add("CAFU.Core.Presentation.View"); parameter.UsingList.Add($"{this.CreateNamespacePrefix()}{ParentLayerType.ToString()}.{LayerType.Presenter.ToString()}"); var generator = new ScriptGenerator(parameter, CreateTemplatePath(TemplateType.Class, StructureName)); generator.Generate(CreateOutputPath(parameter)); new Presenter(CurrentSceneNameIndex, HasPresenterFactory).Generate(overwrite); }
/// <summary> /// 处理一张表 Handle A table. /// </summary> /// <param name="result">Result.</param> public static bool HandleATable(DataTable result, string name) { string[] types = null; string[] names = null; string[] bewrites = null; List <ConfigData[]> dataList = new List <ConfigData[]>(); int index = 1; //开始读取 while (excelReader.Read()) { //这里读取的是每一行的数据 string[] datas = new string[excelReader.FieldCount]; for (int j = 0; j < excelReader.FieldCount; ++j) { datas[j] = excelReader.GetString(j); } //空行不处理 if (datas.Length == 0 || string.IsNullOrEmpty(datas[0])) { ++index; continue; } //第几行表示类型 if (index == PROPERTY_Type_LINE) { types = datas; } //第几行表示变量名 else if (index == PROPERTY_Name_LINE) { names = datas; } //第几行表示描述 else if (index == PROPERTY_Bewrite_LINE) { bewrites = datas; } //后面的表示数据 else if (index > PROPERTY_Bewrite_LINE) { //把读取的数据和数据类型,名称保存起来,后面用来动态生成类 List <ConfigData> configDataList = new List <ConfigData>(); for (int j = 0; j < datas.Length; ++j) { ConfigData data = new ConfigData(); data.Type = types[j]; data.Name = names[j]; data.Data = datas[j]; data.Bewrite = bewrites[j]; if (string.IsNullOrEmpty(data.Type) || string.IsNullOrEmpty(data.Data)) { continue; } configDataList.Add(data); } dataList.Add(configDataList.ToArray()); } ++index; } string className = name; //根据刚才的数据来生成C#脚本 ScriptGenerator generator = new ScriptGenerator(className, names, types, bewrites, cuncsurl); generator.Generate(); AssetDatabase.Refresh(); Type temp = Type.GetType(className); // Assembly assembly = Assembly.GetAssembly(temp); // object container = assembly.CreateInstance(className); Serialize(temp, dataList, cunbytesurl); return(true); }
public void Execute() { ScriptGenerator.Generate(assemblyPath, intermediateDirectory, logError, FindPromotionPath); }
public static string GenerateScript(string className, string[] fieldTypeArr, string[] fieldNameArr) { return(ScriptGenerator.Generate(className, fieldTypeArr, fieldNameArr)); }