public T Add <T>(string uniqueIdentifier, T value) where T : ValueBase { if (string.IsNullOrWhiteSpace(uniqueIdentifier)) { throw new ArgumentNullException("uniqueIdentifier"); } if (value == null) { throw new ArgumentNullException("value"); } var lowerUniqueIdentifier = uniqueIdentifier.ToLower(); if (LinkedValues.ContainsKey(lowerUniqueIdentifier)) { return(LinkedValues[lowerUniqueIdentifier] as T); //throw new ArgumentException("An unique identifier with that name already exists!", "uniqueIdentifier"); } if (value.Parent != null) { throw new ArgumentException("Value has already been added to another menu!", "value"); } // Update serilization id of the value value._serializationId = uniqueIdentifier; LinkedValues.Add(lowerUniqueIdentifier, value); ValueContainer.Add(value); return(value); }
public T Get <T>(string uniqueIdentifier) where T : ValueBase { if (string.IsNullOrWhiteSpace(uniqueIdentifier)) { throw new ArgumentNullException("uniqueIdentifier"); } uniqueIdentifier = uniqueIdentifier.ToLower(); return(LinkedValues.ContainsKey(uniqueIdentifier) ? LinkedValues[uniqueIdentifier].Cast <T>() : null); }
public ValueBase this[string uniqueIdentifier] { get { if (string.IsNullOrWhiteSpace(uniqueIdentifier)) { throw new ArgumentNullException("uniqueIdentifier"); } uniqueIdentifier = uniqueIdentifier.ToLower(); return(LinkedValues.ContainsKey(uniqueIdentifier) ? LinkedValues[uniqueIdentifier] : null); } }
public void Remove(string uniqueIdentifier) { if (string.IsNullOrWhiteSpace(uniqueIdentifier)) { throw new ArgumentNullException("uniqueIdentifier"); } uniqueIdentifier = uniqueIdentifier.ToLower(); if (LinkedValues.ContainsKey(uniqueIdentifier)) { Remove(LinkedValues[uniqueIdentifier]); LinkedValues.Remove(uniqueIdentifier); } }