public void Add(TKey key, TValue value) { string stringKey = getStringKey(key); keys.Add(stringKey, key); values.Add(stringKey, value); }
public bool TryGetValue(TKey key, out TValue value) { object result; if (values.TryGetValue(key, out result)) { value = (TValue)result; return(true); } if (resolveValue != null) { value = resolveValue(key); values.Add(key, value); return(true); } if (unsetValues.Contains(key)) { value = DefaultValue; return(false); } if (tryResolveValue(key, out value)) { values.Add(key, value); return(true); } unsetValues.Add(key); value = DefaultValue; return(false); }
public bool Add(T item) { string stringItem = getStringItem(item); if (items.ContainsKey(stringItem)) { return(false); } items.Add(stringItem, item); return(true); }
public void OverrideMetadata(Type forType, PropertyMetadata metadata) { if (typeMetadata.ContainsKey(forType)) { throw new Granular.Exception("DependencyProperty \"{0}\" already contains metadata for type \"{1}\"", this, forType.Name); } if (metadata.DefaultValue == null) { metadata.DefaultValue = ownerMetadata.DefaultValue; } if (metadata.CoerceValueCallback == null) { metadata.CoerceValueCallback = ownerMetadata.CoerceValueCallback; } if (Inherits != metadata.Inherits) { throw new Granular.Exception("Overriding inheritance behavior is not supported, Overrides of \"{0}\" must declare \"inherits: {1}\"", this, Inherits); } if (Inherits) { if (metadata.DefaultValue != null && metadata.DefaultValue != ownerMetadata.DefaultValue) { throw new Granular.Exception("Overriding inherited properties metadata with different default value is not supported, Overrides of \"{0}\" cannot set a different default value other than \"{1}\"", this, ownerMetadata.DefaultValue); } metadata.DefaultValue = ownerMetadata.DefaultValue; } typeMetadata.Add(forType, metadata); typeMetadataCache.Clear(); orderedTypeMetadataCache = null; isMetadataOverridden = true; }
private DependencyProperty(DependencyPropertyHashKey hashKey, Type propertyType, PropertyMetadata metadata, ValidateValueCallback validateValueCallback, bool isAttached, bool isReadOnly) { this.hashKey = hashKey; this.Name = hashKey.Name; this.OwnerType = hashKey.Owner; this.PropertyType = propertyType; this.ValidateValueCallback = validateValueCallback; this.IsReadOnly = isReadOnly; this.Inherits = metadata.Inherits; this.StringKey = hashKey.StringKey; this.hashCode = hashKey.GetHashCode(); this.ownerMetadata = metadata; this.IsAttached = isAttached; typeMetadata = new ConvertedStringDictionary <Type, PropertyMetadata>(type => type.FullName); typeMetadata.Add(OwnerType, ownerMetadata); typeMetadataCache = CacheDictionary <Type, PropertyMetadata> .CreateUsingStringKeys(ResolveTypeMetadata, type => type.FullName); typeContainsCache = CacheDictionary <Type, bool> .CreateUsingStringKeys(ResolveTypeContains, type => type.FullName); }