// // This method // 1. Ensures that the desired per-instance storage // for Style/Template exists // 2. Also allows you to specify initial capacity // internal static HybridDictionary EnsureInstanceData( UncommonField<HybridDictionary[]> dataField, DependencyObject container, InstanceStyleData dataType, int initialSize) { Debug.Assert((container is FrameworkElement) || (container is FrameworkContentElement), "Caller has queried with non-framework element. Bad caller, bad!"); Debug.Assert(dataType < InstanceStyleData.ArraySize, "Caller has queried using a value outside the range of the Enum. Bad caller, bad!"); HybridDictionary[] data = dataField.GetValue(container); if (data == null) { data = new HybridDictionary[(int)InstanceStyleData.ArraySize]; dataField.SetValue(container, data); } if (data[(int)dataType] == null ) { if( initialSize < 0 ) { data[(int)dataType] = new HybridDictionary(); } else { data[(int)dataType] = new HybridDictionary(initialSize); } } return (HybridDictionary)data[(int)dataType]; }
// // This method // 1. Ensures that the desired per-instance storage // for Style/Template exists // internal static HybridDictionary EnsureInstanceData( UncommonField<HybridDictionary[]> dataField, DependencyObject container, InstanceStyleData dataType) { return EnsureInstanceData(dataField, container, dataType, -1); }