public void GenerateHttpService(Type type, string path, Type controllerType, bool isSearchInterfaces = true, bool includeModule = false) { var parser = new Parser() { IsFindInterface = isSearchInterfaces, Assembly = Assembly }; var properties = type.GetProperties(); var tsVMModel = new TSViewModelTemplate() { Name = type.Name, Properties = new Dictionary <string, string>() }; foreach (var item in properties) { var propertyInfo = parser.Convert(item.PropertyType, isSearchInterfaces); var propertyName = propertyInfo.ValueTypeNullable ? item.Name + "?" : item.Name; tsVMModel.Properties.Add(propertyName, propertyInfo.TypeName); } var data = new List <TSViewModelTemplate>() { tsVMModel }; var startIndex = controllerType.Name.IndexOf("Controller"); var ctrlName = controllerType.Name.Remove(startIndex); var tmpl = new HttpServiceTemplate() { Type = data.First(), ClassName = ctrlName, }; var res = tmpl.TransformText(); var savePath = string.Format("{0}\\{1}{2}.ts", path, ctrlName, "Service"); System.IO.File.WriteAllText(savePath, res); }
public void GenerateViewModelSimple(List <Type> types, string path, bool isSearchInterfaces = true, bool includeModule = false) { var parser = new Parser() { IsFindInterface = isSearchInterfaces, Assembly = Assembly }; var data = new List <TSViewModelTemplate>(); foreach (var cType in types) { var properties = cType.GetProperties(); var tsVMModel = new TSViewModelTemplate() { Name = cType.Name, Properties = new Dictionary <string, string>() }; foreach (var item in properties) { var propertyInfo = parser.Convert(item.PropertyType, isSearchInterfaces); var propertyName = propertyInfo.ValueTypeNullable ? item.Name + "?" : item.Name; tsVMModel.Properties.Add(propertyName, propertyInfo.TypeName); } data.Add(tsVMModel); } var generator = new ViewModelTemplate() { Types = data }; var template = generator.TransformText(); var savePath = string.Format("{0}\\{1}.ts", path, "ViewModels"); System.IO.File.WriteAllText(savePath, template); }