public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo) { foreach (var item in generationInfo.GetTables()) { Create(codeNamespace, item, generationInfo); } }
private static void CreateFieldsTable(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo) { foreach (var item in generationInfo.GetTables(true)) { var cmf = new CodeMemberField(); cmf.Attributes = MemberAttributes.Public; cmf.Name = item.Name; cmf.Type = item.GetCodeType(CodeType.Pointer | CodeType.Const); classType.Members.Add(cmf); } }
private static void CreateDestructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo) { var cc = new CodeDestructor(); cc.Attributes = MemberAttributes.Public | MemberAttributes.Override; foreach (var item in generationInfo.GetTables()) { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name); var delete = new CodeObjectDeleteExpression(field); cc.Statements.Add(delete); } classType.Members.Add(cc); }
private static void CreateConstructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo) { var cc = new CodeConstructor(); cc.Attributes = MemberAttributes.Public; cc.Parameters.Add(generationInfo.ReaderNamespace, "idataset&", "dataSet"); cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision"); foreach (var item in generationInfo.GetTables(true)) { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name); cc.Statements.AddAssign(field, new CodePrimitiveExpression(null)); } var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", new CodeVariableReferenceExpression("dataSet"), new CodeVariableReferenceExpression("verifyRevision")); cc.Statements.Add(methodInvokeExp); classType.Members.Add(cc); }
public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo) { codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------")); codeNamespace.Comments.Add(new CodeCommentStatement($"dataBase: {generationInfo.DataBaseName}")); codeNamespace.Comments.Add(new CodeCommentStatement($"revision: {generationInfo.Revision}")); codeNamespace.Comments.Add(new CodeCommentStatement($"requested revision: {generationInfo.RequestedRevision}")); codeNamespace.Comments.Add(new CodeCommentStatement($"devmode: {generationInfo.IsDevmode}")); codeNamespace.Comments.Add(new CodeCommentStatement($"hash value: {generationInfo.TablesHashValue}")); codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}")); codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------")); foreach (var item in generationInfo.GetTables()) { CremaTableClassCreator.Create(codeNamespace, item, generationInfo); } var classType = new CodeTypeDeclaration(); codeNamespace.Types.Add(classType); classType.Name = generationInfo.ClassName; classType.IsClass = true; classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaData"); CreateNameField(classType, generationInfo); CreateRevisionField(classType, generationInfo); CreateTypesHashValueField(classType, generationInfo); CreateTablesHashValueField(classType, generationInfo); CreateTagsField(classType, generationInfo); CreateNameMethod(classType, generationInfo); CreateRevisionMethod(classType, generationInfo); CreateTypesHashValueMethod(classType, generationInfo); CreateTablesHashValueMethod(classType, generationInfo); CreateTagsMethod(classType, generationInfo); CreateFieldsTable(classType, generationInfo); CreateConstructor(classType, generationInfo); CreateConstructorFromFile(classType, generationInfo); CreateLoadFromFile(classType, generationInfo); CreateLoad(classType, generationInfo); CreateDestructor(classType, generationInfo); }
private static void CreateLoad(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo) { var cc = new CodeMemberMethod(); cc.Attributes = MemberAttributes.Public | MemberAttributes.Final; cc.Name = "Load"; cc.Parameters.Add(generationInfo.ReaderNamespace, "idataset&", "dataSet"); cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision"); var dataSet = new CodeVariableReferenceExpression("dataSet"); { var ccs = CreateCompareDataBaseStatement(classType, generationInfo); var tst = CreateTryCatchStatement(classType, ccs, generationInfo); cc.Statements.Add(tst); } { var ccs = CreateCompareRevisionStatement(classType, generationInfo); var tst = CreateTryCatchStatement(classType, ccs, generationInfo); cc.Statements.Add(tst); } { var ccs = CreateCompareTypesHashValueStatement(classType, generationInfo); var tst = CreateTryCatchStatement(classType, ccs, generationInfo); cc.Statements.Add(tst); } { var ccs = CreateCompareTablesHashValueStatement(classType, generationInfo); var tst = CreateTryCatchStatement(classType, ccs, generationInfo); cc.Statements.Add(tst); } { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_name"); var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "name")); cc.Statements.AddAssign(field, property); } { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_revision"); var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "revision")); cc.Statements.AddAssign(field, property); } { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_typesHashValue"); var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "types_hash_value")); cc.Statements.AddAssign(field, property); } { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tablesHashValue"); var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tables_hash_value")); cc.Statements.AddAssign(field, property); } { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tags"); var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tags")); cc.Statements.AddAssign(field, property); } foreach (var item in generationInfo.GetTables(true)) { var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name); var operatorExp = new CodeBinaryOperatorExpression(field, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); var ccs = new CodeConditionStatement(operatorExp); var delete = new CodeObjectDeleteExpression(field); ccs.TrueStatements.Add(delete); cc.Statements.Add(ccs); var tableName = new CodePrimitiveExpression(item.Name); var tablesProp = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tables")); var table = new CodeIndexerExpression(tablesProp, tableName); //var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name); var instance = new CodeObjectCreateExpression(item.GetCodeType(generationInfo.Namespace, CodeType.None), table); cc.Statements.AddAssign(field, instance); } classType.Members.Add(cc); }