예제 #1
0
 private static void CreateTableFields(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetTables(true))
     {
         var cmf = new CodeMemberField()
         {
             Attributes = MemberAttributes.Private,
             Name       = item.GetFieldName(),
             Type       = item.GetCodeType()
         };
         classType.Members.Add(cmf);
     }
 }
예제 #2
0
        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($"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()
            {
                Attributes = MemberAttributes.Public,
                Name       = generationInfo.ClassName,
                IsClass    = true
            };

            classType.TypeAttributes |= TypeAttributes.Sealed;
            classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaData");

            CreateNameField(classType, generationInfo);
            CreateRevisionField(classType, generationInfo);
            CreateTypesHashValueField(classType, generationInfo);
            CreateTablesHashValueField(classType, generationInfo);
            CreateTagsField(classType, generationInfo);
            CreateNameProperty(classType, generationInfo);
            CreateRevisionProperty(classType, generationInfo);
            CreateTypesHashValueProperty(classType, generationInfo);
            CreateTablesHashValueProperty(classType, generationInfo);
            CreateTagsProperty(classType, generationInfo);
            CreateTableFields(classType, generationInfo);
            CreateConstructor(classType, generationInfo);
            CreateConstructorFromFile(classType, generationInfo);
            CreateConstructorFromStream(classType, generationInfo);
            CreateLoadFromFile(classType, generationInfo);
            CreateLoadStream(classType, generationInfo);
            CreateLoad(classType, generationInfo);
            CreateTableProperties(classType, generationInfo);

            codeNamespace.Types.Add(classType);
        }
예제 #3
0
        private static void CreateTableProperties(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetTables(true))
            {
                var cmp = new CodeMemberProperty()
                {
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    Name       = item.GetPropertyName(),
                    Type       = item.GetCodeType(),
                    HasGet     = true,
                    HasSet     = false
                };
                cmp.Comments.AddSummary(item.Comment);
                cmp.GetStatements.AddMethodReturn(item.GetFieldExpression());

                classType.Members.Add(cmp);
            }
        }
예제 #4
0
        private static void CreateLoad(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeMemberMethod()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = "Load",
            };

            cc.Parameters.Add("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 field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_name");
                var property = new CodePropertyReferenceExpression(dataSet, "Name");
                cc.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_revision");
                var property = new CodePropertyReferenceExpression(dataSet, "Revision");
                cc.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_typesHashValue");
                var property = new CodePropertyReferenceExpression(dataSet, "TypesHashValue");
                cc.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tablesHashValue");
                var property = new CodePropertyReferenceExpression(dataSet, "TablesHashValue");
                cc.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tags");
                var property = new CodePropertyReferenceExpression(dataSet, "Tags");
                cc.Statements.AddAssign(field, property);
            }

            foreach (var item in generationInfo.GetTables(true))
            {
                var tableName  = new CodePrimitiveExpression(item.Name);
                var tablesProp = new CodePropertyReferenceExpression(dataSet, "Tables");
                var table      = new CodeIndexerExpression(tablesProp, tableName);

                var field           = item.GetFieldExpression();
                var instance        = new CodeObjectCreateExpression(item.GetCodeType(), table);
                var assignStatement = new CodeAssignStatement(field, instance);

                cc.Statements.Add(assignStatement);
            }

            classType.Members.Add(cc);
        }