A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.5 KiB

// -----------------------------------------------------------------------
// <copyright file="FuncTemplate`2.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.Templates
{
using System;
/// <summary>
/// Creates a control from a <see cref="Func{TParam, TControl}"/>.
/// </summary>
/// <typeparam name="TParam">The type of the parameter.</typeparam>
/// <typeparam name="TControl">The type of control.</typeparam>
public class FuncTemplate<TParam, TControl> : ITemplate<TParam, TControl>
where TControl : IControl
{
private Func<TParam, TControl> func;
/// <summary>
/// Initializes a new instance of the <see cref="FuncTemplate{TControl, TParam}"/> class.
/// </summary>
/// <param name="func">The function used to create the control.</param>
public FuncTemplate(Func<TParam, TControl> func)
{
Contract.Requires<ArgumentNullException>(func != null);
this.func = func;
}
/// <summary>
/// Creates the control.
/// </summary>
/// <param name="param">The parameter.</param>
/// <returns>
/// The created control.
/// </returns>
public TControl Build(TParam param)
{
return this.func(param);
}
}
}