GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — bytecode-api/BytecodeApi.Wpf/ConverterBase.cs at master · bytecode77/bytecode-api Expand file tree/ Copy pathConverterBase.csMore file actions 112 lines (105 loc) · 4.61 KB / Copy pathConverterBase.csFile metadata and controls112 lines (105 loc) · 4.61 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Markup; namespace BytecodeApi.Wpf; /// <summary> /// Represents the base class that wraps the <see cref="IValueConverter" /> and provides a simplified wrapper method for Convert. ConvertBack always returns <see cref="DependencyProperty.UnsetValue" />. This is an abstract class. /// </summary> /// <typeparam name="TValue">The type of the value to convert.</typeparam> public abstract class ConverterBase<TValue> : MarkupExtension, IValueConverter { /// <summary> /// Specifies a converter that is used to convert the result of this converter. This can be used to apply multiple conversions on a value. /// </summary> public IValueConverter? Then { get; set; } /// <summary> /// If <see cref="Then" /> is not <see langword="null" />, specifies a converter parameter that is used to convert the result of this converter. /// </summary> public object? ThenParameter { get; set; } /// <summary> /// Initializes a new instance of the <see cref="ConverterBase{TValue}" /> class. /// </summary> protected ConverterBase() { } /// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <returns> /// A converted value. If the method returns <see langword="null" />, the valid null value is used. /// </returns> public abstract object? Convert(TValue? value); object? IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { object? result = Convert(CSharp.CastOrDefault<TValue>(value)); return Then == null ? result : Then.Convert(result, targetType, ThenParameter, culture); } object? IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } /// <summary> /// Returns this instance of <see cref="IValueConverter" />. /// </summary> /// <param name="serviceProvider">Object that can provide services for the markup extension.</param> /// <returns> /// This instance of <see cref="IValueConverter" />. /// </returns> public sealed override object ProvideValue(IServiceProvider serviceProvider) { return this; } } /// <summary> /// Represents the base class that wraps the <see cref="IValueConverter" /> and provides a simplified wrapper method for Convert. ConvertBack always returns <see cref="DependencyProperty.UnsetValue" />. This is an abstract class. /// </summary> /// <typeparam name="TValue">The type of the value to convert.</typeparam> /// <typeparam name="TParameter">The type of the parameter used for conversion.</typeparam> public abstract class ConverterBase<TValue, TParameter> : MarkupExtension, IValueConverter { /// <summary> /// Specifies a converter that is used to convert the result of this converter. This can be used to apply multiple conversions on a value. /// </summary> public IValueConverter? Then { get; set; } /// <summary> /// If <see cref="Then" /> is not <see langword="null" />, specifies a converter parameter that is used to convert the result of this converter. /// </summary> public object? ThenParameter { get; set; } /// <summary> /// Initializes a new instance of the <see cref="ConverterBase{TValue, TParameter}" /> class. /// </summary> protected ConverterBase() { } /// <summary> /// Converts a value. /// </summary> /// <param name="value">The value produced by the binding source.</param> /// <param name="parameter">The converter parameter to use.</param> /// <returns> /// A converted value. If the method returns <see langword="null" />, the valid null value is used. /// </returns> public abstract object? Convert(TValue? value, TParameter? parameter); object? IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { object? result = Convert(CSharp.CastOrDefault<TValue>(value), CSharp.CastOrDefault<TParameter>(parameter)); return Then == null ? result : Then.Convert(result, targetType, ThenParameter, culture); } object? IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return DependencyProperty.UnsetValue; } /// <summary> /// Returns this instance of <see cref="IValueConverter" />. /// </summary> /// <param name="serviceProvider">Object that can provide services for the markup extension.</param> /// <returns> /// This instance of <see cref="IValueConverter" />. /// </returns> public sealed override object ProvideValue(IServiceProvider serviceProvider) { return this; } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |