public T GetExtendedProperty(string nameSpace, string name) { if (nameSpace == null) { throw new ArgumentNullException("nameSpace"); } if (name == null) { throw new ArgumentNullException("name"); } T result = default(T); Dictionary <string, T> dictionary = this.propertyStore[nameSpace]; if (MessageTraceCollapsedProperty.IsCollapsableProperty(nameSpace, name)) { IEnumerable <PropertyBase> source; if (!ExtendedPropertyStore <T> .TryGetCollapsedProperties(dictionary, nameSpace, name, out source)) { throw new KeyNotFoundException(string.Format(CultureInfo.InvariantCulture, "The key '{0}' was not found in the property bag", new object[] { name })); } result = (T)((object)source.LastOrDefault((PropertyBase p) => string.Equals(p.PropertyName, name, StringComparison.OrdinalIgnoreCase))); } else { result = dictionary[name]; } return(result); }
public bool TryGetExtendedProperty(string nameSpace, string name, out T extendedProperty) { if (nameSpace == null) { throw new ArgumentNullException("nameSpace"); } if (name == null) { throw new ArgumentNullException("name"); } Dictionary <string, T> dictionary = null; if (this.propertyStore.TryGetValue(nameSpace, out dictionary) && dictionary.TryGetValue(name, out extendedProperty)) { if (!MessageTraceCollapsedProperty.IsCollapsableProperty(nameSpace, name)) { return(true); } IEnumerable <PropertyBase> source; if (ExtendedPropertyStore <T> .TryGetCollapsedProperties(dictionary, nameSpace, name, out source)) { extendedProperty = (source.LastOrDefault((PropertyBase p) => string.Equals(p.PropertyName, name, StringComparison.OrdinalIgnoreCase)) as T); if (extendedProperty != null) { return(true); } } } extendedProperty = default(T); return(false); }