예제 #1
0
        private void ExecuteTemplateDtoBase(TableInfo tableInfo, Context configContext, IEnumerable <Info> infos)
        {
            var pathOutput = PathOutput.PathOutputDto(tableInfo, configContext);

            if ((File.Exists(pathOutput) && tableInfo.CodeCustomImplemented))
            {
                return;
            }

            var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "dto");

            if (!File.Exists(pathTemplateClass))
            {
                return;
            }

            var pathTemplatePropertys = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "models.property");
            var textTemplateClass     = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var TextTemplatePropertys = Read.AllText(tableInfo, pathTemplatePropertys, this._defineTemplateFolder);


            var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass);

            var classBuilderPropertys = string.Empty;

            if (infos.IsAny())
            {
                foreach (var item in infos)
                {
                    if (Audit.IsAuditField(item.PropertyName))
                    {
                        continue;
                    }

                    if (item.IsKey == 1)
                    {
                        classBuilder = classBuilder.Replace("<#KeyName#>", item.PropertyName);
                        var cast = item.Type == "string" ? ".ToString()" : string.Empty;
                        classBuilder = classBuilder.Replace("<#toString()#>", cast);
                        var expressionInclusion = item.Type == "string" ? string.Format("string.IsNullOrEmpty(this.{0})", item.PropertyName) : string.Format("this.{0} == 0", item.PropertyName);
                    }

                    var itempropert = TextTemplatePropertys.
                                      Replace("<#type#>", item.Type).
                                      Replace("<#propertyName#>", item.PropertyName);

                    classBuilderPropertys += string.Format("{0}{1}{2}", Tabs.TabModels(), itempropert, System.Environment.NewLine);
                }
            }

            classBuilder = classBuilder.Replace("<#property#>", classBuilderPropertys);


            using (var stream = new StreamWriter(pathOutput))
            {
                stream.Write(classBuilder);
            }
        }