private string EntityStruct() { var code = new StringBuilder(); bool isFirst = true; foreach (PropertyConfig col in Table.PublishProperty) { if (isFirst) { isFirst = false; } else { code.Append(','); } code.AppendFormat(@" {{ Real_{0}, new PropertySturct {{ Index = Index_{0}, PropertyName = ""{0}"", PropertyType = typeof({1}), CanNull = {2}, ValueType = PropertyValueType.{3} }} }}", col.PropertyName , col.CustomType ?? col.CsType , col.Nullable ? "true" : "false" , CodeBuilderDefault.PropertyValueType(col)); } var code2 = new StringBuilder(); foreach (PropertyConfig col in Table.PublishProperty) { code2.AppendFormat(@" public const byte Index_{0} = {1};", col.PropertyName, col.Index); } return(string.Format(@" {3} /// <summary> /// 实体结构 /// </summary> [IgnoreDataMember,Browsable (false)] public override EntitySturct __Struct {{ get {{ return __struct; }} }} /// <summary> /// 实体结构 /// </summary> [IgnoreDataMember] static readonly EntitySturct __struct = new EntitySturct {{ EntityName = ""{0}"", PrimaryKey = ""{1}"", Properties = new Dictionary<int, PropertySturct> {{{2} }} }}; " , Table.EntityName, Table.PrimaryColumn.PropertyName, code, code2)); }
private string DJson() { var code = new StringBuilder(); bool isUser = Table.PublishProperty.Any(p => p.IsUserId); foreach (var col in Table.PublishProperty) { if (isUser && col.IsPrimaryKey) { col.ClientType = col.CsType; } else if (string.IsNullOrEmpty(col.ClientType)) { continue; } string type = col.ClientType.Trim(); string name = string.IsNullOrEmpty(col.ClientName) ? col.PropertyName : col.ClientName; if (type[type.Length - 1] == '?') { if (type.Contains("DateTime")) { code.AppendFormat(@" if (value.ContainsKey(""{0}"")) {{ var v1 = value[""{0}""]; if(v1 != null && !string.IsNullOrEmpty(v1.ToString())) entity.{0} =GetTime(v1); }}" , name); } else { code.AppendFormat(@" if (value.ContainsKey(""{0}"")) {{ var v1 = value[""{0}""]; if(v1 != null && !string.IsNullOrEmpty(v1.ToString())) entity.{0} = Convert.To{1}(v1); }}" , name , CodeBuilderDefault.ToNetFrameType(type)); } } else if (type.Contains("DateTime")) { code.AppendFormat(@" if (value.ContainsKey(""{0}"")) entity.{0} =GetTime(value[""{0}""]);" , name); } else { code.AppendFormat(@" if (value.ContainsKey(""{0}"")) entity.{0} = Convert.To{1}(value[""{0}""]);" , name , CodeBuilderDefault.ToNetFrameType(type)); } if (!col.Nullable) { code.AppendFormat(@" #if DEBUG else throw new Exception(""{1}表{0}字段值丢失""); #endif" , Table.EntityName , name); } } return(code.ToString()); }