public static void RemoveValue(TTextView textView, object key) { if (textView.Properties.TryGetProperty(typeof(AutoClosingViewProperty <TProperty, TTextView>), out AutoClosingViewProperty <TProperty, TTextView> properties)) { properties.Remove(key); } }
public static bool GetOrCreateValue( TTextView textView, object key, Func <TTextView, TProperty> valueCreator, out TProperty value ) { Contract.ThrowIfTrue(textView.IsClosed); var properties = textView.Properties.GetOrCreateSingletonProperty( () => new AutoClosingViewProperty <TProperty, TTextView>(textView) ); if (!properties.TryGetValue(key, out var priorValue)) { // Need to create it. value = valueCreator(textView); properties.Add(key, value); return(true); } // Already there. value = priorValue; return(false); }
public static void AddValue(TTextView textView, object key, TProperty value) { Contract.ThrowIfTrue(textView.IsClosed); var properties = textView.Properties.GetOrCreateSingletonProperty( () => new AutoClosingViewProperty <TProperty, TTextView>(textView) ); properties.Add(key, value); }
public static bool TryGetValue( TTextView textView, object key, [MaybeNullWhen(false)] out TProperty value) { Contract.ThrowIfTrue(textView.IsClosed); var properties = textView.Properties.GetOrCreateSingletonProperty(() => new AutoClosingViewProperty <TProperty, TTextView>(textView)); return(properties.TryGetValue(key, out value)); }
private AutoClosingViewProperty(TTextView textView) { _textView = textView; _textView.Closed += OnTextViewClosed; }