public static void WriteClassProperties(Type classType, string outputFolder) { var className = classType.Name.Replace("`1", ""); if (GenedClasses.Contains(classType.Namespace + "." + className)) { return; } GenedClasses.Add(classType.Namespace + "." + className); if (classType.GetGenericArguments().Length > 0) { foreach (var genericArgument in classType.GetGenericArguments()) { if (!genericArgument.IsEnum) { WriteClassProperties(genericArgument, outputFolder); } if (genericArgument.IsEnum) { WriteEnum(genericArgument, outputFolder); } } } var useTypeT = classType.IsConstructedGenericType; var folderName = classType.Namespace.Replace(".", @"\"); var pathBuilder = new StringBuilder(outputFolder); pathBuilder.AppendFormat(@"{0}\", folderName); if (!Directory.Exists(pathBuilder.ToString())) { try { Directory.CreateDirectory(pathBuilder.ToString()); } catch (Exception e) { Console.WriteLine(e); } } if (!File.Exists(pathBuilder + className + ".cs")) { var creator = new ClassCreator(classType.Namespace); creator.SetClassName(className, useTypeT); foreach (var prop in classType.GetProperties()) { if (prop.PropertyType.IsGenericType) { foreach (var t in prop.PropertyType.GetGenericArguments()) { if (t.IsClass && !t.FullName.StartsWith("System")) { WriteClassProperties(t, outputFolder); } if (t.IsEnum && !t.FullName.StartsWith("System")) { WriteEnum(t, outputFolder); } } creator.AddProperties(prop.Name, prop.PropertyType); } else { if (prop.PropertyType.IsClass && !prop.PropertyType.FullName.StartsWith("System")) { WriteClassProperties(prop.PropertyType, outputFolder); } creator.AddProperties(prop.Name, prop.PropertyType); } } creator.GenerateCSharpCode(pathBuilder + className + ".cs"); } }
public static void WriteClassProperties(Type classType, string outputFolder) { var className = classType.Name.Replace("`1", ""); if (GenedClasses.Contains(classType.Namespace + "." + className)) return; GenedClasses.Add(classType.Namespace + "." + className); if (classType.GetGenericArguments().Length > 0) { foreach (var genericArgument in classType.GetGenericArguments()) { if (!genericArgument.IsEnum) { WriteClassProperties(genericArgument, outputFolder); } if (genericArgument.IsEnum) { WriteEnum(genericArgument, outputFolder); } } } var useTypeT = classType.IsConstructedGenericType; var folderName = classType.Namespace.Replace(".", @"\"); var pathBuilder = new StringBuilder(outputFolder); pathBuilder.AppendFormat(@"{0}\", folderName); if (!Directory.Exists(pathBuilder.ToString())) { try { Directory.CreateDirectory(pathBuilder.ToString()); } catch (Exception e) { Console.WriteLine(e); } } if (!File.Exists(pathBuilder + className + ".cs")) { var creator = new ClassCreator(classType.Namespace); creator.SetClassName(className, useTypeT); foreach (var prop in classType.GetProperties()) { if (prop.PropertyType.IsGenericType) { foreach (var t in prop.PropertyType.GetGenericArguments()) { if (t.IsClass && !t.FullName.StartsWith("System")) { WriteClassProperties(t, outputFolder); } if (t.IsEnum && !t.FullName.StartsWith("System")) { WriteEnum(t, outputFolder); } } creator.AddProperties(prop.Name, prop.PropertyType); } else { if (prop.PropertyType.IsClass && !prop.PropertyType.FullName.StartsWith("System")) { WriteClassProperties(prop.PropertyType, outputFolder); } creator.AddProperties(prop.Name, prop.PropertyType); } } creator.GenerateCSharpCode(pathBuilder + className + ".cs"); } }
public static void WriteClassProperties(Type classType, string outputFolder) { var className = classType.Name.Replace("`1", ""); if (!File.Exists(outputFolder + className + ".cs")) { var creator = new ClassCreator(classType.Namespace); if (classType.GetGenericArguments().Length > 0) { foreach (var genericArgument in classType.GetGenericArguments()) { if (!genericArgument.IsEnum) { WriteClassProperties(genericArgument, outputFolder); } if (genericArgument.IsEnum) { WriteEnum(genericArgument, outputFolder); } } } var useTypeT = classType.IsConstructedGenericType; creator.SetClassName(className, useTypeT); foreach (var prop in classType.GetProperties()) { if (prop.PropertyType.IsGenericType) { foreach (var t in prop.PropertyType.GetGenericArguments()) { if (t.IsClass && !t.FullName.StartsWith("System")) { WriteClassProperties(t, outputFolder); } if (t.IsEnum && !t.FullName.StartsWith("System")) { WriteEnum(t, outputFolder); } } creator.AddProperties(prop.Name, prop.PropertyType); } else { if (prop.PropertyType.IsClass && !prop.PropertyType.FullName.StartsWith("System")) { WriteClassProperties(prop.PropertyType, outputFolder); } creator.AddProperties(prop.Name, prop.PropertyType); } } creator.GenerateCSharpCode(outputFolder + className + ".cs"); } }