/// <summary> /// 更新包含子项的项模式 /// </summary> /// <param name="name">项名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> /// <param name="childSchema">如果类型是BizStructure或者BizStructureArray,那么该属性有效,表示子结构</param> public void Update( string name, string displayName, BizDataType bizDataType, BizStructureSchema childSchema) { base.Update(name, displayName, bizDataType, UnlimitedMaxLength, null); this._ChildSchema = childSchema; }
/// <summary> /// 更新不包含子结构的对象的项 /// </summary> /// <param name="name">项名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> /// <param name="maxLength">最大长度,比如字符串类型,是可以设置长度限制的</param> /// <param name="DefaultValue">默认值</param> public void Update( string name, string displayName, BizDataType bizDataType, int maxLength, object defaultValue) { base.Update(name, displayName, bizDataType, maxLength, DefaultValue); }
/// <summary> /// 创建的时候使用 /// </summary> /// <param name="name">项目名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> public NamedItemSchema( string name, string displayName, BizDataType bizDataType) { this._Name = name; this._DisplayName = displayName; this._DataType = bizDataType; }
/// <summary> /// 创建不包含子结构的对象的项 /// </summary> /// <param name="name">项名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> public ItemSchema( string name, string displayName, BizDataType bizDataType) : base( name, displayName, bizDataType) { this._ChildSchema = null; }
/// <summary> /// 将逻辑类型转换为实际类型 /// </summary> /// <param name="type">逻辑类型</param> /// <returns>运行态的类型</returns> public static System.Type ToRealType(BizDataType type) { switch (type) { case BizDataType.Bool: return(typeof(bool)); case BizDataType.DateTime: return(typeof(System.DateTime)); case BizDataType.TimeSpan: return(typeof(System.TimeSpan)); case BizDataType.Double: return(typeof(double)); case BizDataType.Int: return(typeof(int)); case BizDataType.Long: return(typeof(long)); case BizDataType.UnitArray: return(typeof(string[])); case BizDataType.ShortString: case BizDataType.Map: case BizDataType.Address: case BizDataType.String: case BizDataType.Unit: case BizDataType.Html: case BizDataType.Xml: case BizDataType.Association: return(typeof(string)); case BizDataType.ByteArray: return(typeof(byte[])); //case BizDataType.File: // return typeof(DataModel.BizObjectFile[]); //case BizDataType.BizObject: // return typeof(DataModel.BizObject); //case BizDataType.BizObjectArray: // return typeof(DataModel.BizObject[]); case BizDataType.BizStructure: return(typeof(BizBus.BizStructure)); case BizDataType.BizStructureArray: return(typeof(BizBus.BizStructure[])); default: throw new NotImplementedException(); } }
/// <summary> /// 创建不包含子结构的对象的项 /// </summary> /// <param name="name">项名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> /// <param name="maxLength">最大长度,比如字符串类型,是可以设置长度限制的</param> /// <param name="DefaultValue">默认值</param> public ItemSchema( string name, string displayName, BizDataType bizDataType, int maxLength, object DefaultValue) : base( name, displayName, bizDataType, maxLength, DefaultValue) { this._ChildSchema = null; }
/// <summary> /// 创建包含子结构的项的时候使用 /// </summary> /// <param name="name">项名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> /// <param name="childSchema">如果类型是BizStructure或者BizStructureArray,那么该属性有效,表示子结构</param> public ItemSchema( string name, string displayName, BizDataType bizDataType, BizStructureSchema childSchema) : base( name, displayName, bizDataType, UnlimitedMaxLength, null) { this._ChildSchema = childSchema; }
/// <summary> /// 更新项目属性模式 /// </summary> /// <param name="name">项目名称</param> /// <param name="displayName">显示名称</param> /// <param name="bizDataType">类型</param> /// <param name="maxLength">最大长度</param> /// <param name="defaultValue">默认值</param> public void Update( string name, string displayName, BizDataType bizDataType, int maxLength, object defaultValue) { this._Name = name; this._DisplayName = displayName; this._DataType = bizDataType; this._MaxLength = maxLength; // 检查默认值是否符合类型要求 this._DefaultValue = defaultValue; }
private static bool JObjectToSchema(JObject jobject, out BizStructureSchema schema, out string errorMessage) { errorMessage = null; schema = new BizStructureSchema(); foreach (KeyValuePair <string, JToken> keyValuePair in jobject) { if (keyValuePair.Value == null) { continue; } if (string.Compare(keyValuePair.Key, "code", true) == 0) { schema.Code = keyValuePair.Value.ToString(); continue; } if (!(keyValuePair.Value is JArray)) { errorMessage = keyValuePair.Value.ToString() + "不合法"; return(false); } JArray itemObject = (JArray)keyValuePair.Value; string name = keyValuePair.Key; string displayName = null; string strDataType = null; BizDataType dataType = BizDataType.ShortString; BizStructureSchema childSchema = null; foreach (JObject childObject in itemObject) { foreach (KeyValuePair <string, JToken> itemKeyValuePair in childObject) { if (string.Compare(itemKeyValuePair.Key, "name", true) == 0) { name = itemKeyValuePair.Value.ToString(); } else if (string.Compare(itemKeyValuePair.Key, "displayname", true) == 0) { displayName = itemKeyValuePair.Value.ToString(); } else if (string.Compare(itemKeyValuePair.Key, "datatype", true) == 0) { strDataType = itemKeyValuePair.Value.ToString(); try { dataType = (BizDataType)Enum.Parse(typeof(BizDataType), strDataType, true); } catch { errorMessage = string.Format("字段类型{0}不合法", strDataType); return(false); } } else if (string.Compare(itemKeyValuePair.Key, "childschema", true) == 0) { if (itemKeyValuePair.Value != null && !string.IsNullOrEmpty(itemKeyValuePair.Value.ToString())) { if (!(itemKeyValuePair.Value is JObject)) { errorMessage = string.Format("字段{0}不合法", itemKeyValuePair.Value.ToString()); return(false); } JObject childJObject = (JObject)itemKeyValuePair.Value; if (!JObjectToSchema(childJObject, out childSchema, out errorMessage)) { return(false); } } } } if (string.IsNullOrEmpty(displayName)) { displayName = name; } ItemSchema itemSchema = new ItemSchema(name, displayName, dataType, childSchema); schema.Add(itemSchema); } } return(true); }