Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ValueConverterBase.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Globalization;
5 using System.Windows.Data;
6 using System.Windows.Markup;
7 
8 namespace SiliconStudio.Presentation.ValueConverters
9 {
10  /// <summary>
11  /// An abstract class for implementations of <see cref="IValueConverter"/> that supports markup extensions.
12  /// </summary>
13  /// <typeparam name="T">The type of <see cref="IValueConverter"/> being implemented.</typeparam>
14  public abstract class ValueConverterBase<T> : MarkupExtension, IValueConverter where T : class, IValueConverter, new()
15  {
16  private static T valueConverterInstance;
17 
18  /// <summary>
19  /// Initializes a new instance of the <see cref="ValueConverterBase{T}"/> class.
20  /// </summary>
21  /// <exception cref="InvalidOperationException">The generic argument does not match the type of the implementation of this class.</exception>
22  protected ValueConverterBase()
23  {
24  if (GetType() != typeof(T)) throw new InvalidOperationException("The generic argument of this class must be the type being implemented.");
25  }
26 
27  /// <inheritdoc/>
28  public override object ProvideValue(IServiceProvider serviceProvider)
29  {
30  return valueConverterInstance ?? (valueConverterInstance = new T());
31  }
32 
33  /// <inheritdoc/>
34  public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
35 
36  /// <inheritdoc/>
37  public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
38  }
39 }
ValueConverterBase()
Initializes a new instance of the ValueConverterBase{T} class.
override object ProvideValue(IServiceProvider serviceProvider)
HRESULT Convert(_In_ const Image &srcImage, _In_ DXGI_FORMAT format, _In_ DWORD filter, _In_ float threshold, _Out_ ScratchImage &image)