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(ValueBase value) { if (value == null) { throw new ArgumentNullException("value"); } ValueContainer.Remove(value); foreach (var entry in LinkedValues.Where(entry => entry.Value == value).ToArray()) { LinkedValues.Remove(entry.Key); break; } }
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); } }
private void AddImpl(string name, object value) { var v = _Dictionary[name]; if (v == null) { _Dictionary.Add(name, value); } else { _Dictionary[name] = new LinkedValues { Value = value, Next = v, Index = (v is LinkedValues) ? ((LinkedValues)v).Length() : 1 }; } }