public static CharacterPropertiesContractRegistry GetOrCreateContract(this Character character, uint contractId, ReaderWriterLockSlim rwLock, out bool contractWasCreated) { rwLock.EnterWriteLock(); try { var entity = character.CharacterPropertiesContractRegistry.FirstOrDefault(c => c.ContractId == contractId); if (entity == null) { entity = new CharacterPropertiesContractRegistry { ContractId = contractId }; character.CharacterPropertiesContractRegistry.Add(entity); contractWasCreated = true; } else { contractWasCreated = false; } return(entity); } finally { rwLock.ExitWriteLock(); } }
public static bool EraseContract(this Character character, uint contractId, out CharacterPropertiesContractRegistry contractErased, ReaderWriterLockSlim rwLock) { rwLock.EnterWriteLock(); try { contractErased = character.CharacterPropertiesContractRegistry.FirstOrDefault(c => c.ContractId == contractId); if (contractErased == null) { return(false); } character.CharacterPropertiesContractRegistry.Remove(contractErased); return(true); } finally { rwLock.ExitWriteLock(); } }