private static void CreateChildProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo) { foreach (var item in generationInfo.GetChilds(tableInfo)) { var cmp = new CodeMemberProperty(); cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final; cmp.Name = item.TableName; cmp.Type = item.GetCodeType(); cmp.HasGet = true; cmp.HasSet = false; // return field { var fieldExp = item.GetFieldExpression(); cmp.GetStatements.AddMethodReturn(fieldExp); } cmp.Comments.AddSummary(item.Comment); classType.Members.Add(cmp); } }
private static void CreateSetChildsMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo) { foreach (var item in generationInfo.GetChilds(tableInfo)) { var cmm = new CodeMemberMethod(); cmm.Attributes = MemberAttributes.FamilyAndAssembly | MemberAttributes.Static; cmm.Name = "Set" + item.TableName; cmm.Parameters.Add(tableInfo.GetRowCodeType(), "target"); cmm.Parameters.Add(typeof(string), "childName"); cmm.Parameters.Add(item.GetRowCodeType(), 1, "childs"); // invoke setParent { var target = new CodeVariableReferenceExpression("target"); var childs = new CodeVariableReferenceExpression("childs"); var setParent = new CodeMethodReferenceExpression(tableInfo.GetRowCodeTypeExpression(), "setParent"); setParent.TypeArguments.Add(tableInfo.GetRowCodeType()); setParent.TypeArguments.Add(item.GetRowCodeType()); var invokeSetParent = new CodeMethodInvokeExpression(setParent, target, childs); cmm.Statements.AddExpression(invokeSetParent); } // create and assign child table { var target = new CodeVariableReferenceExpression("target"); var childName = new CodeVariableReferenceExpression("childName"); var childs = new CodeVariableReferenceExpression("childs"); var field = item.GetFieldExpression(target); var createFromRows = new CodeMethodReferenceExpression(item.GetCodeTypeExpression(), "createFromRows"); var InvokeCreateFromRows = new CodeMethodInvokeExpression(createFromRows, childName, childs); cmm.Statements.AddAssign(field, InvokeCreateFromRows); } classType.Members.Add(cmm); } }