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