public static void SetProperty(this Biota biota, PropertyDataId property, uint value, ReaderWriterLockSlim rwLock) { rwLock.EnterUpgradeableReadLock(); try { var result = biota.BiotaPropertiesDID.FirstOrDefault(x => x.Type == (uint)property); if (result != null) { result.Value = value; } else { rwLock.EnterWriteLock(); try { var entity = new BiotaPropertiesDID { ObjectId = biota.Id, Type = (ushort)property, Value = value, Object = biota }; biota.BiotaPropertiesDID.Add(entity); } finally { rwLock.ExitWriteLock(); } } } finally { rwLock.ExitUpgradeableReadLock(); } }
public static void SetProperty(this Biota biota, PropertyDataId property, uint value) { var result = biota.BiotaPropertiesDID.FirstOrDefault(x => x.Type == (uint)property); if (result != null) result.Value = value; else { var entity = new BiotaPropertiesDID { ObjectId = biota.Id, Type = (ushort)property, Value = value, Object = biota }; biota.BiotaPropertiesDID.Add(entity); } }
public static bool TryRemoveProperty(this Biota biota, PropertyDataId property, out BiotaPropertiesDID entity, ReaderWriterLockSlim rwLock) { rwLock.EnterUpgradeableReadLock(); try { entity = biota.BiotaPropertiesDID.FirstOrDefault(x => x.Type == (uint)property); if (entity != null) { rwLock.EnterWriteLock(); try { biota.BiotaPropertiesDID.Remove(entity); entity.Object = null; return(true); } finally { rwLock.ExitWriteLock(); } } return(false); } finally { rwLock.ExitUpgradeableReadLock(); } }
public static bool TryRemoveProperty(this Biota biota, PropertyDataId property, out BiotaPropertiesDID entity) { entity = biota.BiotaPropertiesDID.FirstOrDefault(x => x.Type == (uint)property); if (entity != null) { biota.BiotaPropertiesDID.Remove(entity); entity.Object = null; return true; } return false; }