public string GenerateClassFileFromAssembly(string className) { var type = _types.SingleOrDefault(t => t.Name == className); Properties = type.GetProperties().ToList(); ClassName = type.Name; if (type.IsEnum) { var enumFileGenerator = new EnumJsonTranslator(Namespace, ClassName, type); return(enumFileGenerator.TransformText()); } else { var constructor = type.GetConstructor(Type.EmptyTypes); if (constructor == null) { var fileGenerator = new ClassWithConstructorArguments(type.GetProperties().ToList(), Namespace, type.Name, type.GetConstructors()); return(fileGenerator.TransformText()); } else { var fileGenerator = new FileGenerator(type.GetProperties().ToList(), Namespace, type.Name); return(fileGenerator.TransformText()); } } }
public Dictionary <string, string> TransformFiles() { var fileDictionary = new Dictionary <string, string>(); var typesTobeConverted = _assembly.GetTypes(); foreach (var type in typesTobeConverted) { var fileGenerator = new FileGenerator(type.GetProperties().ToList(), Namespace, type.Name); fileDictionary.Add(type.Name, fileGenerator.TransformText()); } return(fileDictionary); }
public string GenerateClassFileFromAssembly(string className) { var type = _types.SingleOrDefault(t => t.Name == className); Properties = type.GetProperties().ToList(); ClassName = type.Name; if (type.IsEnum) { var enumFileGenerator = new EnumJsonTranslator(Namespace, ClassName, type); return(enumFileGenerator.TransformText()); } else { var fileGenerator = new FileGenerator(type.GetProperties().ToList(), Namespace, type.Name); return(fileGenerator.TransformText()); } }
public void TestTransform() { string path = @"D:\Tavisca.USG.Cars.StateTranslators\"; var fileGenerator = new FileGenerator(Assembly.LoadFrom(@"D:\Model.dll"), "Tavisca.USG.Cars.StateTranslators"); var files = fileGenerator.TransformFiles(); foreach (var fileName in files.Keys) { try { var parts = fileName.Split('.'); Directory.CreateDirectory(path + parts[parts.Length - 2]); File.WriteAllText(path + parts.Last() + "Translator.cs", files[fileName]); } catch (Exception ex) { //File.WriteAllText(path + new Random(1000).Next().ToString() + "Translator.cs", files[fileName]); Console.WriteLine(ex.ToString()); } } Console.WriteLine("Done"); }