/// <summary>
        /// Gets a value of of the property specified by name from ConfigDictionary.
        /// </summary>
        /// <param name="propertyId">Name of the property to retrieve.</param>
        /// <param name="md">Dictionary (data source) containing the data for the property.</param>
        /// <exception cref="PropertyRetrievalException">Thrown when either data source is null or when the data source does not contain the string value for the specified property name.</exception>
        private static Property GetConfigDictionaryProperty(LocResource.LocResourceProps propertyId, ConfigDictionary md)
        {
            if (md == null)
            {
                throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "DataSource must not be null. DataSource name: {0}", md.GetType().Name));
            }
            string value;

            md.TryGetValue(propertyId.ToString(), out value);
            switch (propertyId)
            {
            case LocResource.LocResourceProps.ResourceId:
                return(new StringProperty((byte)propertyId, value));

            case LocResource.LocResourceProps.SourceString:
                return(new StringProperty((byte)propertyId, value));

            case LocResource.LocResourceProps.Comments:
                return(new StringProperty((byte)propertyId, value));

            case LocResource.LocResourceProps.FilePath:
                return(new StringProperty((byte)propertyId, value));

            default: throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "Cannot provide property {0} from datasource of type {1}.", propertyId.ToString(), md.GetType().Name));
            }
        }
예제 #2
0
 private void ForEachProperty(Action <IConfigPropertyBase> action)
 {
     if (ConfigDictionary.TryGetValue(this, out IndexDictionary <String, IConfigPropertyBase> dictionary))
     {
         dictionary.Values.ToList().ForEach(action);
     }
 }
예제 #3
0
        public static void RemoveProperty(IConfigPropertyBase property)
        {
            if (!ConfigDictionary.TryGetValue(property.Config, out IndexDictionary <String, IConfigPropertyBase> dictionary))
            {
                return;
            }

            dictionary.Remove(property.Path);
            ClearProperty(property);
        }
예제 #4
0
        protected T Get <T>(string name, T defaultValue)
        {
            object result;

            if (ConfigDictionary.TryGetValue(name, out result))
            {
                return((T)result);
            }
            return(defaultValue);
        }
예제 #5
0
 public IEnumerable <IConfigPropertyBase> GetProperties()
 {
     return(ConfigDictionary.TryGetValue(this, out IndexDictionary <String, IConfigPropertyBase> dictionary) ? dictionary.Values : null);
 }
예제 #6
0
 public void ClearProperties()
 {
     ForEachProperty(ClearProperty);
     ConfigDictionary.TryGetValue(this)?.Clear();
 }