public int Delete <T>(List <T> ListEntity) { int _Iret = 0; foreach (T EntityItem in ListEntity) { string sID = EntityItem.GetType().GetProperty("id").GetValue(EntityItem).ToString(); int iID = Convert.ToInt32(sID); bool _ret = this._repo.Delete <T>(iID); if (_ret) { _Iret++; } } return(_Iret); }
/// <summary> /// Serialize a unique EntityItem /// </summary> /// <param name="item">EntityItem to serialize</param> /// <returns>Entity item as string</returns> public override string SerializeItem(EntityItem <object> item) { string parts = null; string strType = null; string strContainer = null; string strValue = null; Type type = null; var itemSerialize = ItemsSerialize .Where(f => f.CanSerialize(this, item)) .LastOrDefault(); if (itemSerialize != null) { var info = itemSerialize.GetSerializeInfo(this, item); type = info.Type; strContainer = info.ContainerName; } if (type != null) { if (ShowType == ShowTypeOptions.TypeNameOnlyInRoot && item.GetType() == typeof(ComplexEntity)) { strType = type.Name; } else if (ShowType == ShowTypeOptions.TypeName) { strType = type.Name; } else if (ShowType == ShowTypeOptions.FullTypeName) { strType = type.FullName; } } if (!string.IsNullOrWhiteSpace(strType) && string.IsNullOrWhiteSpace(strContainer)) { parts = $"{strType}"; } else if (!string.IsNullOrWhiteSpace(strType) && !string.IsNullOrWhiteSpace(strContainer)) { parts = $"{strType}{Constants.IDENTIFIER_SEPARATOR}{strContainer}"; } else if (string.IsNullOrWhiteSpace(strType) && !string.IsNullOrWhiteSpace(strContainer)) { parts = $"{strContainer}"; } // Get value strValue = ValueFormatter.Format(type, item.Entity); // When is not primitive entity use hashcode var separatorValue = $"{Constants.KEY_VALUE_SEPARATOR} "; if (strValue == null && item.Entity != null) { // get entityId strValue = GetEntityIdCallback?.Invoke(item).ToString() ?? item.Entity.GetHashCode().ToString(); separatorValue = Constants.IDENTIFIER_SEPARATOR; } else if (strValue == null) { separatorValue = null; } if (string.IsNullOrWhiteSpace(parts)) { separatorValue = null; } return($"{parts}{separatorValue}{strValue}"); }