/// <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)); } }
private void ForEachProperty(Action <IConfigPropertyBase> action) { if (ConfigDictionary.TryGetValue(this, out IndexDictionary <String, IConfigPropertyBase> dictionary)) { dictionary.Values.ToList().ForEach(action); } }
public static void RemoveProperty(IConfigPropertyBase property) { if (!ConfigDictionary.TryGetValue(property.Config, out IndexDictionary <String, IConfigPropertyBase> dictionary)) { return; } dictionary.Remove(property.Path); ClearProperty(property); }
protected T Get <T>(string name, T defaultValue) { object result; if (ConfigDictionary.TryGetValue(name, out result)) { return((T)result); } return(defaultValue); }
public IEnumerable <IConfigPropertyBase> GetProperties() { return(ConfigDictionary.TryGetValue(this, out IndexDictionary <String, IConfigPropertyBase> dictionary) ? dictionary.Values : null); }
public void ClearProperties() { ForEachProperty(ClearProperty); ConfigDictionary.TryGetValue(this)?.Clear(); }