Exemple #1
0
        public void Compile(string outputPath, GenerationSet metaData, CodeGenerationSettings settings, string target)
        {
            var path           = PathUtility.GetFullPath(outputPath);
            var generationInfo = new CodeGenerationInfo(path, metaData, settings);

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == false && settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false)
            {
                var filename = this.CompileAll(path, generationInfo, target);
                this.PrintResult(filename);
            }
            else if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == true)
            {
                var filename = this.CompileBase(path, generationInfo, target);
                this.PrintResult(filename);
            }
            else if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == true)
            {
                var tempPath = PathUtility.GetTempPath(true);
                try
                {
                    var readerPath = this.CompileBase(tempPath, generationInfo, target);
                    var filename   = this.Compile(path, readerPath, generationInfo, target);
                    this.PrintResult(filename);
                }
                finally
                {
                    DirectoryUtility.Delete(tempPath);
                }
            }
        }
        public static void Create(CodeNamespace codeNamespace, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration()
            {
                Attributes = MemberAttributes.Public,
                Name       = tableInfo.GetRowClassName(),
                IsClass    = true
            };

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

            CreateChildStaticEmptyFields(classType, tableInfo, generationInfo);
            CreateConstructor(classType, tableInfo, generationInfo);
            CreateTableField(classType, tableInfo);
            CreateColumnFields(classType, tableInfo, generationInfo);
            CreateChildFields(classType, tableInfo, generationInfo);

            CreateSetChildsMethod(classType, tableInfo, generationInfo);
            CreateColumnProperties(classType, tableInfo, generationInfo);
            CreateChildProperties(classType, tableInfo, generationInfo);
            CreateTableProperty(classType, tableInfo);
            CreateParentProperty(classType, tableInfo);

            codeNamespace.Types.Add(classType);
        }
Exemple #3
0
        public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings)
        {
            var path           = PathUtility.GetFullPath(outputPath);
            var generationInfo = new CodeGenerationInfo(path, metaData, settings);

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == false)
            {
                var codes = this.GenerateCodes(generationInfo);
                foreach (var item in codes)
                {
                    var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, path, item.Key);
                    this.PrintResult(codePath);
                }
            }

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false)
            {
                var codes = this.GenerateBaseCodes(generationInfo);
                foreach (var item in codes)
                {
                    var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, path, item.Key);
                    this.PrintResult(codePath);
                }
            }
        }
Exemple #4
0
        private string GenerateReader(CodeGenerationInfo generationInfo)
        {
            var assembly     = System.Reflection.Assembly.GetExecutingAssembly();
            var resourceName = string.Join(".", this.GetType().Namespace, "Code", "CremaReader.cs");
            var code         = this.GetResourceString(resourceName);

            code = code.Replace("namespace JSSoft.Crema.Code", "namespace " + generationInfo.BaseNamespace);
            code = code.Replace("JSSoft.Crema.Reader", generationInfo.ReaderNamespace);
            return(code);
        }
        private static void CreateTagsField(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmf = new CodeMemberField
            {
                Attributes = MemberAttributes.Private,
                Name       = "_tags",
                Type       = new CodeTypeReference(typeof(string))
            };

            classType.Members.Add(cmf);
        }
 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);
     }
 }
        private static void CreateTagsProperty(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberProperty
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = "Tags",
                HasGet     = true,
                Type       = new CodeTypeReference(typeof(string))
            };

            cmm.GetStatements.AddMethodReturn(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_tags"));

            classType.Members.Add(cmm);
        }
        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.TypesHashValue}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));

            foreach (var item in generationInfo.Types)
            {
                CreateType(codeNamespace, item, generationInfo);
            }
        }
        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);
        }
Exemple #10
0
        private IDictionary <string, string> GenerateCodes(CodeGenerationInfo generationInfo)
        {
            var codes = new Dictionary <string, string>();

            var cremaTypes  = this.GenerateTypeCode(generationInfo);
            var cremaTables = this.GenerateTableCode(generationInfo);

            codes.Add($"{generationInfo.Prefix}Types{generationInfo.Postfix}.cs", cremaTypes);
            codes.Add($"{generationInfo.Prefix}Tables{generationInfo.Postfix}.cs", cremaTables);

            foreach (var item in codes.ToArray())
            {
                codes[item.Key] = item.Value.Replace("JSSoft.Crema.Reader", generationInfo.ReaderNamespace);
            }

            return(codes);
        }
Exemple #11
0
        private string GenerateTypeCode(CodeGenerationInfo generationInfo)
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                var codeDomProvider = new CSharpCodeProvider();
                var codeGenerator   = codeDomProvider.CreateGenerator(sw);
                var compileUnit     = new CodeCompileUnit();
                var codeNamespace   = new CodeNamespace(generationInfo.Namespace);
                codeNamespace.Imports.Add(new CodeNamespaceImport(generationInfo.ReaderNamespace));
                CremaTypeEnumCreator.Create(codeNamespace, generationInfo);
                compileUnit.Namespaces.Add(codeNamespace);
                codeGenerator.GenerateCodeFromCompileUnit(compileUnit, sw, this.options);
            }

            return(sb.ToString());
        }
        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);
            }
        }
Exemple #13
0
        private string CompileAll(string outputPath, CodeGenerationInfo generationInfo, string target)
        {
            var sourceList = new List <string>();

            sourceList.AddRange(this.GenerateCodes(generationInfo).Values);
            sourceList.AddRange(this.GenerateBaseCodes(generationInfo).Values);

            sourceList.Add(this.GenerateAssemblyInfo(generationInfo.Namespace));

            var providerOptions = new Dictionary <string, string>
            {
                { "CompilerVersion", target == string.Empty ? "v3.5" : target }
            };
            var codeDomProvider = new CSharpCodeProvider(providerOptions);

            var cp = new CompilerParameters()
            {
                OutputAssembly     = Path.Combine(outputPath, generationInfo.Namespace + ".dll"),
                CompilerOptions    = "/optimize",
                GenerateExecutable = false,
                GenerateInMemory   = false
            };

            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Core.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");

            FileUtility.Prepare(cp.OutputAssembly);

            var result = codeDomProvider.CompileAssemblyFromSource(cp, sourceList.ToArray());

            if (result.Errors.HasErrors)
            {
                foreach (var item in result.Errors)
                {
                    Trace.WriteLine(item);
                }

                throw new Exception("에러가 발생했습니다.");
            }

            return(cp.OutputAssembly);
        }
        private static void CreateConstructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add("IDataSet", "dataSet");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            //cc.BaseConstructorArgs.Add(new CodePrimitiveExpression(generationInfo.DataBaseName));
            //cc.BaseConstructorArgs.Add(new CodePrimitiveExpression(generationInfo.Revision));

            var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", new CodeVariableReferenceExpression("dataSet"), new CodeVariableReferenceExpression("verifyRevision"));

            cc.Statements.Add(methodInvokeExp);

            classType.Members.Add(cc);
        }
        private static void CreateConstructorFromFile(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add(typeof(string), "filename");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            var readerRef       = new CodeTypeReferenceExpression(string.Join(".", generationInfo.ReaderNamespace, "CremaReader"));
            var paramExp        = new CodeVariableReferenceExpression("filename");
            var methodInvokeExp = new CodeMethodInvokeExpression(readerRef, "Read", paramExp);

            cc.ChainedConstructorArgs.Add(methodInvokeExp);
            cc.ChainedConstructorArgs.Add(new CodeVariableReferenceExpression("verifyRevision"));

            classType.Members.Add(cc);
        }
        private static void CreateLoadStream(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeMemberMethod()
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = "Load",
            };

            cc.Parameters.Add(typeof(Stream), "stream");
            cc.Parameters.Add(typeof(bool), "verifyRevision");

            var readerRef = new CodeTypeReferenceExpression(string.Join(".", generationInfo.ReaderNamespace, "CremaReader"));
            var paramExp  = new CodeVariableReferenceExpression("stream");
            var readExp   = new CodeMethodInvokeExpression(readerRef, "Read", paramExp);

            var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", readExp, new CodeVariableReferenceExpression("verifyRevision"));

            cc.Statements.Add(methodInvokeExp);

            classType.Members.Add(cc);
        }
Exemple #17
0
        private IDictionary <string, string> GenerateBaseCodes(CodeGenerationInfo generationInfo)
        {
            var codes = new Dictionary <string, string>
            {
                { $"{generationInfo.RelativePath}CremaBase.cs", this.GenerateBase(generationInfo) },
                { $"{generationInfo.RelativePath}CremaReader.cs", this.GenerateReader(generationInfo) }
            };

            //var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            //var ns = string.Join(".", this.GetType().Namespace, "Reader");
            //var files = assembly.GetManifestResourceNames().Where(item => item.StartsWith(ns));

            //foreach (var item in files)
            //{
            //    var value = this.GetResourceString(item);
            //    var key = Regex.Replace(item, "(^" + this.GetType().Namespace + @"[.])(\S+)[.]cs", "$2").Replace('.', Path.DirectorySeparatorChar);
            //    value = value.Replace("JSSoft.Crema.Reader", generationInfo.ReaderNamespace);
            //    codes.Add($"{generationInfo.RelativePath}{key}.cs", value);
            //}

            return(codes);
        }
        public static CodeStatement CreateTryCatchStatement(CodeTypeDeclaration classType, CodeStatement statement, CodeGenerationInfo generationInfo)
        {
            var tryStatement = new CodeTryCatchFinallyStatement();

            tryStatement.TryStatements.Add(statement);

            var catchClause     = new CodeCatchClause("e");
            var methodRefExp    = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression($"{generationInfo.BaseNamespace}.CremaData"), "InvokeErrorOccuredEvent");
            var methodInvokeExp = new CodeMethodInvokeExpression(methodRefExp, new CodeThisReferenceExpression(), new CodeVariableReferenceExpression("e"));

            var conditionStatement = new CodeConditionStatement()
            {
                Condition = new CodeBinaryOperatorExpression(methodInvokeExp, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false))
            };

            conditionStatement.TrueStatements.Add(new CodeThrowExceptionStatement(new CodeVariableReferenceExpression("e")));

            catchClause.Statements.Add(conditionStatement);
            tryStatement.CatchClauses.Add(catchClause);

            return(tryStatement);
        }
        private static CodeStatement CreateCompareRevisionStatement(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var ccs = new CodeConditionStatement();

            var left1  = new CodeVariableReferenceExpression("verifyRevision");
            var right1 = new CodePrimitiveExpression(true);
            var left   = new CodeBinaryOperatorExpression(left1, CodeBinaryOperatorType.IdentityEquality, right1);

            var left2  = new CodeCastExpression(typeof(string), new CodePrimitiveExpression(generationInfo.Revision));
            var right2 = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("dataSet"), "Revision");
            var right  = new CodeBinaryOperatorExpression(left2, CodeBinaryOperatorType.IdentityInequality, right2);

            ccs.Condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.BooleanAnd, right);

            var message   = string.Format("데이터의 리비전 코드 리비전({0})과 다릅니다.", generationInfo.Revision);
            var exception = new CodeObjectCreateExpression(typeof(Exception), new CodePrimitiveExpression(message));

            ccs.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(ccs);
        }
        private static CodeStatement CreateCompareDataBaseStatement(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var ccs = new CodeConditionStatement();

            var left  = new CodePrimitiveExpression(generationInfo.DataBaseName);
            var right = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("dataSet"), "Name");

            ccs.Condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, right);

            var message   = string.Format("데이터의 이름이 코드 이름({0})과 다릅니다.", generationInfo.DataBaseName);
            var exception = new CodeObjectCreateExpression(typeof(Exception), new CodePrimitiveExpression(message));

            ccs.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(ccs);
        }
        public static void CreateTypeMember(CodeTypeDeclaration classType, TypeMemberInfo typeMemberInfo, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberField()
            {
                Name           = typeMemberInfo.Name,
                InitExpression = new CodePrimitiveExpression((int)typeMemberInfo.Value)
            };

            if (generationInfo.OmitComment == false)
            {
                cmm.Comments.AddSummary(typeMemberInfo.Comment);
            }

            if (generationInfo.OmitSignatureDate == false)
            {
                cmm.Comments.Add(CremaSchema.Creator, typeMemberInfo.CreationInfo.ID);
                cmm.Comments.Add(CremaSchema.CreatedDateTime, typeMemberInfo.CreationInfo.DateTime);
                cmm.Comments.Add(CremaSchema.Modifier, typeMemberInfo.ModificationInfo.ID);
                cmm.Comments.Add(CremaSchema.ModifiedDateTime, typeMemberInfo.ModificationInfo.DateTime);
            }

            classType.Members.Add(cmm);
        }
        private static void CreateSetChildsMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmm = new CodeMemberMethod()
                {
                    Attributes = MemberAttributes.FamilyAndAssembly | MemberAttributes.Static,
                    Name       = "Set" + item.TableName
                };
                cmm.Parameters.Add(tableInfo.GetRowCodeType(), "target");
                cmm.Parameters.Add(typeof(string), "childName");
                cmm.Parameters.Add(item.GetRowCodeType(), 1, "childs");

                {
                    var methodRefExp = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(tableInfo.GetRowCodeType()), "SetParent");
                    methodRefExp.TypeArguments.Add(tableInfo.GetRowCodeType());
                    methodRefExp.TypeArguments.Add(item.GetRowCodeType());

                    var methodInvokeExp = new CodeMethodInvokeExpression(methodRefExp, new CodeVariableReferenceExpression("target"), new CodeVariableReferenceExpression("childs"));

                    cmm.Statements.AddExpression(methodInvokeExp);
                }

                {
                    var target         = new CodeVariableReferenceExpression("target");
                    var childName      = new CodeVariableReferenceExpression("childName");
                    var childs         = new CodeVariableReferenceExpression("childs");
                    var targetField    = item.GetFieldExpression(target);
                    var targetInstance = new CodeObjectCreateExpression(item.GetCodeType(), childName, childs);
                    cmm.Statements.AddAssign(targetField, targetInstance);
                }

                classType.Members.Add(cmm);
            }
        }
        private static void CreateColumnProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in tableInfo.Columns)
            {
                var cmp = new CodeMemberProperty()
                {
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    Name       = item.Name,
                    Type       = item.GetCodeType()
                };
                if (generationInfo.OmitComment == false)
                {
                    cmp.Comments.AddSummary(item.Comment);
                }
                if (generationInfo.OmitSignatureDate == false)
                {
                    cmp.Comments.Add(CremaSchema.Creator, item.CreationInfo.ID);
                    cmp.Comments.Add(CremaSchema.CreatedDateTime, item.CreationInfo.DateTime);
                    cmp.Comments.Add(CremaSchema.Modifier, item.ModificationInfo.ID);
                    cmp.Comments.Add(CremaSchema.ModifiedDateTime, item.ModificationInfo.DateTime);
                }
                cmp.HasGet = true;
                cmp.HasSet = false;
                cmp.GetStatements.AddMethodReturn(item.GetFieldExpression());

                classType.Members.Add(cmp);
            }
        }
 private static void CreateColumnFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
 {
     foreach (var item in tableInfo.Columns)
     {
         var cmf = new CodeMemberField()
         {
             Attributes = MemberAttributes.Private,
             Name       = item.GetFieldName(),
             Type       = item.GetCodeType()
         };
         classType.Members.Add(cmf);
     }
 }
        private static void CreateConstructor(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add(generationInfo.ReaderNamespace, "IRow", "row");
            cc.Parameters.Add(tableInfo.GetCodeType(), "table");
            cc.BaseConstructorArgs.Add("row");

            // assign table field
            {
                var leftExp  = tableInfo.GetFieldExpression();
                var rightExp = new CodeVariableReferenceExpression("table");
                cc.Statements.AddAssign(leftExp, rightExp);
            }

            // assign fields
            {
                var index = 0;
                foreach (var item in tableInfo.Columns)
                {
                    var cas = new CodeAssignStatement()
                    {
                        Left  = item.GetFieldExpression(),
                        Right = item.GetGetValueMethodExpression(index, false)
                    };
                    if (item.IsKey == false)
                    {
                        var ccs = new CodeConditionStatement(item.GetHasValueMethodExpression(index, false));
                        ccs.TrueStatements.Add(cas);
                        cc.Statements.Add(ccs);
                    }
                    else
                    {
                        cc.Statements.Add(cas);
                    }
                    index++;
                }
            }

            // invoke SetKey method
            {
                var methodRefExp    = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "SetKey");
                var methodInvokeExp = new CodeMethodInvokeExpression(methodRefExp);

                foreach (var item in tableInfo.Columns)
                {
                    if (item.IsKey == true)
                    {
                        var getHashCode = new CodeMethodReferenceExpression(item.GetFieldExpression(), "GetHashCode");
                        methodInvokeExp.Parameters.Add(new CodeMethodInvokeExpression(getHashCode));
                    }
                }
                cc.Statements.Add(methodInvokeExp);
            }

            classType.Members.Add(cc);
        }
        public static void CreateType(CodeNamespace codeNamespace, TypeInfo typeInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration(typeInfo.Name)
            {
                Attributes = MemberAttributes.Public,
                IsEnum     = true
            };

            if (typeInfo.IsFlag == true)
            {
                classType.CustomAttributes.Add(typeof(FlagsAttribute));
            }

            if (generationInfo.OmitComment == false)
            {
                classType.Comments.AddSummary(typeInfo.Comment);
            }

            if (generationInfo.OmitSignatureDate == false)
            {
                classType.Comments.Add(CremaSchema.Creator, typeInfo.CreationInfo.ID);
                classType.Comments.Add(CremaSchema.CreatedDateTime, typeInfo.CreationInfo.DateTime);
                classType.Comments.Add(CremaSchema.Modifier, typeInfo.ModificationInfo.ID);
                classType.Comments.Add(CremaSchema.ModifiedDateTime, typeInfo.ModificationInfo.DateTime);
            }

            foreach (var item in typeInfo.Members)
            {
                CreateTypeMember(classType, item, generationInfo);
            }

            codeNamespace.Types.Add(classType);
        }
        private static void CreateConstructorFromStream(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor()
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add(typeof(Stream), "stream");
            cc.Parameters.Add(typeof(bool), "verifyRevision");

            var readerRef       = new CodeTypeReferenceExpression(string.Join(".", generationInfo.ReaderNamespace, "CremaReader"));
            var paramExp        = new CodeVariableReferenceExpression("stream");
            var methodInvokeExp = new CodeMethodInvokeExpression(readerRef, "Read", paramExp);

            cc.ChainedConstructorArgs.Add(methodInvokeExp);
            var left  = new CodeVariableReferenceExpression("verifyRevision");
            var right = new CodePrimitiveExpression(false);

            cc.ChainedConstructorArgs.Add(new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.Assign, right));

            classType.Members.Add(cc);
        }
 private static void CreateChildStaticEmptyFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetChilds(tableInfo))
     {
         var cmf = new CodeMemberField()
         {
             Attributes     = MemberAttributes.Private | MemberAttributes.Static,
             Name           = item.GetFieldName() + "Empty",
             Type           = item.GetCodeType(),
             InitExpression = new CodeObjectCreateExpression(item.GetCodeType())
         };
         classType.Members.Add(cmf);
     }
 }
        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);
        }
        private static void CreateChildProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmp = new CodeMemberProperty()
                {
                    Attributes = MemberAttributes.Public | MemberAttributes.Final,
                    Name       = item.GetPropertyName(),
                    Type       = item.GetCodeType()
                };
                if (generationInfo.OmitComment == false)
                {
                    cmp.Comments.AddSummary(item.Comment);
                }
                if (generationInfo.OmitSignatureDate == false)
                {
                    cmp.Comments.Add(CremaSchema.Creator, item.CreationInfo.ID);
                    cmp.Comments.Add(CremaSchema.CreatedDateTime, item.CreationInfo.DateTime);
                    cmp.Comments.Add(CremaSchema.Modifier, item.ModificationInfo.ID);
                    cmp.Comments.Add(CremaSchema.ModifiedDateTime, item.ModificationInfo.DateTime);
                }
                cmp.HasGet = true;
                cmp.HasSet = false;

                {
                    var state   = new CodeConditionStatement();
                    var testExp = new CodeBinaryOperatorExpression(item.GetFieldExpression(), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));
                    state.Condition = testExp;

                    var staticRefExp = new CodeTypeReferenceExpression(tableInfo.GetRowCodeType());
                    var fieldExp     = new CodeFieldReferenceExpression(staticRefExp, item.GetFieldName() + "Empty");
                    state.TrueStatements.AddMethodReturn(fieldExp);

                    cmp.GetStatements.Add(state);
                }

                {
                    var fieldExp = item.GetFieldExpression();
                    cmp.GetStatements.AddMethodReturn(fieldExp);
                }

                classType.Members.Add(cmp);
            }
        }