Java代码生成完善

This commit is contained in:
陈皓 2018-10-18 10:59:53 +08:00
parent dd54964321
commit 5d914f7034
2 changed files with 46 additions and 11 deletions

View File

@ -60,14 +60,50 @@ namespace CoderEngine
CoderAddLine("public class " + ClassName + " {"); CoderAddLine("public class " + ClassName + " {");
foreach (var tl in TopMode.TypeList) foreach (var tl in TopMode.TypeList)
{
CoderAddLine("");
if (tl.MemberType.Name == "List`1")
{
}
else
{ {
CoderAddLine(tabstr + "@SerializedName(value = \"" + tl.Name + "\")"); CoderAddLine(tabstr + "@SerializedName(value = \"" + tl.Name + "\")");
CoderAddLine(tabstr + "public " + CSharpToJavaTypeName(tl.MemberType) + " " + tl.Name + ";");
} }
CoderAddLine(tabstr + "private " + CSharpToJavaTypeName(tl.MemberType) + " " + tl.Name + ";");
}
CoderAddLine("");
CoderAddLine(tabstr + "//"+ ClassName + "中所有属性对应get set 方法");
foreach (var tl in TopMode.TypeList)
{
CoderAddLine("");
CoderAddLine(tabstr + "public " + CSharpToJavaTypeName(tl.MemberType) + " get" + tl.Name + "(){return " + tl.Name + ";}");
CoderAddLine("");
CoderAddLine(tabstr + "public void set" + tl.Name + "(" + CSharpToJavaTypeName(tl.MemberType) + " " + tl.Name + "){return this." + tl.Name + " = " + tl.Name + ";}");
}
CoderAddLine("");
CoderAddLine(tabstr+"//为该实体类生成的toString打印方法");
CoderAddLine(tabstr+ "@Override");
CoderAddLine(tabstr + "public String toString() {");
CoderAddLine(tabstr + tabstr + "return \"CommentInfoModel{ \" +");
foreach (var tl in TopMode.TypeList)
{
CoderAddLine(tabstr + tabstr + tabstr + "\"" + tl.Name + "='\" + " + tl.Name + " + '\\'' + \",\" ");
}
CoderAddLine(tabstr + tabstr + tabstr + "'}';");
CoderAddLine(tabstr + "}");
CoderAddLine("}"); CoderAddLine("}");
foreach (var tl in TopMode.TypeList) foreach (var tl in TopMode.TypeList)
{ {
if(tl.MemberType.Name == "List`1") if(tl.MemberType.Name == "List`1")
@ -78,7 +114,6 @@ namespace CoderEngine
JavaCodeDownRecursion(tl); JavaCodeDownRecursion(tl);
} }
} }
} }
} }

View File

@ -11,21 +11,21 @@ namespace UseEngineConsolo
public class A public class A
{ {
public int a { get; set; } public string UserID { get; set; }
public int aa { get; set; } public int Sex { get; set; }
public DateTime? date { get; set; } public DateTime? Birthday { get; set; }
public List<B> Blist { get; set; } public List<B> SunList { get; set; }
} }
public class B public class B
{ {
public string b { get; set; } public string SouUserID { get; set; }
public List<C> Clist { get; set; } public List<C> Girlfriends { get; set; }
} }
public class C public class C
{ {
public string string_b { get; set; } public string GirlName { get; set; }
} }
class Program class Program