Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Converters/GenericLambdaConverter.cs @ 12747

Last change on this file since 12747 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Data;
6using System.Globalization;
7using System.Diagnostics.Contracts;
8
9namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
10{
11  public class GenericLambdaConverter<TIn, TOut> : IValueConverter
12  {
13    private readonly Func<TIn, TOut> lambda;
14
15    /// <summary>
16    /// Initializes a new instance of the <see cref="GenericLambdaConverter&lt;TIn, TOut&gt;"/> class.
17    /// </summary>
18    /// <param name="lambda">The lambda.</param>
19    public GenericLambdaConverter(Func<TIn, TOut> lambda)
20    {
21      Contract.Assert(lambda != null);
22
23      this.lambda = lambda;
24    }
25
26    #region IValueConverter Members
27
28    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
29    {
30      TIn arg = (TIn)value;
31      TOut result = lambda(arg);
32      return result;
33    }
34
35    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
36    {
37      throw new NotImplementedException();
38    }
39
40    #endregion
41  }
42}
Note: See TracBrowser for help on using the repository browser.