Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 public ValueBase this[string uniqueIdentifier]
 {
     get
     {
         if (string.IsNullOrWhiteSpace(uniqueIdentifier))
         {
             throw new ArgumentNullException("uniqueIdentifier");
         }
         uniqueIdentifier = uniqueIdentifier.ToLower();
         return(LinkedValues.ContainsKey(uniqueIdentifier) ? LinkedValues[uniqueIdentifier] : null);
     }
 }
Esempio n. 4
0
        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);
            }
        }