private static string GetICollectionPropertyTypeName(ICollectionProperty property) { string typeName = property.PropertyType.Name.Equals("LocalDynamicObjectCollection") ? GetBaseTypeName(property.PropertyType) : $"List<{property.Name}>"; return(typeName); }
public static ContextTypeInfo MakeProperty <TContainer, TValue>(ICollectionProperty <TContainer, TValue> property, ref TContainer container) { return(new ContextTypeInfo() { IsProperty = true, IsPropertyContainer = property.IsContainer, IsCollection = true, CollectionLenth = property.GetCount(ref container), ValueType = typeof(TValue) }); }
public static IEnumerable <ICollectionProperty> GetCollectionProperties(this IDataEntityPropertyCollection properties, bool onlyDbProperty = true) { for (int i = 0; i < properties.Count; i++) { IDataEntityProperty metadata = properties[i]; ICollectionProperty iteratorVariable0 = metadata as ICollectionProperty; if ((iteratorVariable0 != null) && (!onlyDbProperty || !metadata.IsDbIgnore())) { yield return(iteratorVariable0); } } }
private int FindItemIndex(ICollectionProperty property, object entity, object item) { object obj3; ISimpleProperty primaryKey = this._binder.GetDataEntityType(item).PrimaryKey; if (primaryKey == null) { return(-1); } object obj2 = primaryKey.GetValue(item); string oid = (obj2 == null) ? "" : obj2.ToString(); return(this.FindItemByOid(property, entity, oid, out obj3)); }
private bool ReadCollectionProperty(ICollectionProperty property, object entity) { if (property == null) { return(false); } string name = this._reader.Name; while (this.MoveToNextElement(name)) { string action = GetAttributeValue(this._reader, "action", "add"); this.DoCollectionPropertyAction(action, property, entity); } return(true); }
private IList SafeGetList(ICollectionProperty property, object entity) { if (object.ReferenceEquals(this._lastColProperty, property) && object.ReferenceEquals(this._lastColEntity, entity)) { return(this._lastList); } object obj2 = property.GetValue(entity); if (obj2 == null) { if (property.IsReadOnly) { SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("集合属性{0}是只读且未初始化值,请初始化的值或提供Set功能。", "014009000001748", SubSystemType.SL, new object[0]), property.Name), data, null); } try { obj2 = Activator.CreateInstance(property.PropertyType); property.SetValue(entity, obj2); } catch (Exception exception) { SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("自动创建集合属性{0}的值失败,{1}。", "014009000001749", SubSystemType.SL, new object[0]), property.Name, exception.Message), data2, exception); } } IList list = obj2 as IList; if (list == null) { SerializationException.SerializationExceptionData data3 = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("集合属性{0}必须支持IList接口", "014009000001750", SubSystemType.SL, new object[0]), property.Name), data3, null); } this._lastColProperty = property; this._lastColEntity = entity; this._lastList = list; return(list); }
private int FindItemByOid(ICollectionProperty property, object entity, string oid, out object item) { if (string.IsNullOrEmpty(oid)) { SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", ResManager.LoadKDString("试图处理节点却没有指定oid", "014009000001746", SubSystemType.SL, new object[0]), data, null); item = null; return(-2); } ISimpleProperty primaryKey = property.CollectionItemPropertyType.PrimaryKey; if (primaryKey == null) { SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData { CanIgnore = false }; this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("需要处理的集合{0}其元素类型{1}没有定义主键。", "014009000001747", SubSystemType.SL, new object[0]), property.Name, property.CollectionItemPropertyType.Name), data2, null); item = null; return(-2); } object objB = this.ConvertFromString(primaryKey, entity, oid); IList list = this.SafeGetList(property, entity); if (list == null) { item = null; return(-2); } for (int i = 0; i < list.Count; i++) { item = list[i]; if ((item != null) && object.Equals(this._binder.GetDataEntityType(item).PrimaryKey.GetValue(item), objB)) { return(i); } } item = null; return(-1); }
private int FindItemByOid(ICollectionProperty property, object entity, out object item) { string attribute = this._reader.GetAttribute("oid"); return(this.FindItemByOid(property, entity, attribute, out item)); }
private void DoCollectionPropertyAction(string action, ICollectionProperty property, object entity) { string str = action; if (str != null) { if (!(str == "add")) { if (str == "edit") { object obj3; int num2 = this.FindItemByOid(property, entity, out obj3); if (num2 >= 0) { this.ReadElement(property.CollectionItemPropertyType, obj3); } else if (num2 == -1) { SerializationException.SerializationExceptionData data = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", ResManager.LoadKDString("试图编辑的节点在现有集合中没有找到。", "014009000001743", SubSystemType.SL, new object[0]), data, null); } goto Label_0196; } if (str == "remove") { if (!this.OnlyLocaleValue) { object obj4; int index = this.FindItemByOid(property, entity, out obj4); if (index >= 0) { this.SafeGetList(property, entity).RemoveAt(index); } else if (index == -1) { SerializationException.SerializationExceptionData data2 = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", ResManager.LoadKDString("试图删除的节点在现有集合中没有找到。", "014009000001744", SubSystemType.SL, new object[0]), data2, null); } } goto Label_0196; } } else { object obj2 = this.ReadElement(property.CollectionItemPropertyType, null); IList list = this.SafeGetList(property, entity); if (list != null) { if (this._colloctionIgnorePKValue) { list.Add(obj2); } else if (this.FindItemIndex(property, entity, obj2) < 0) { list.Add(obj2); } } goto Label_0196; } } SerializationException.SerializationExceptionData data3 = new SerializationException.SerializationExceptionData { CanIgnore = true }; this.ThrowXmlException("??????", string.Format(ResManager.LoadKDString("不能识别的集合操作符{0}", "014009000001745", SubSystemType.SL, new object[0]), action), data3, null); Label_0196: this.SafeDo(); }