ant-design-blazor/components/core/Extensions/DataConvertionExtensions.cs
Brian Ding 1fa3652d26 feat(module: slider): implement two-way binding (#329)
* feat(module: slider): implement two-way binding

* feat(module: slider): remove mouseup handler

* feat(module: slider): inherits from AntInputComponentBase

* fix(module: slider): onclick will be fired with onmouseup

* feat(module: slider): move convert method to public extensions

* feat(module: slider): update to fit form component

* fix(module: slider): two-way binding does not notify value change

* feat(module: slider): update input demo with two-way binding

* feat(module: slider): remove OnProertyChanged
2020-07-15 20:02:39 +08:00

30 lines
946 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AntDesign.core.Extensions
{
public static class DataConvertionExtensions
{
public static TTo Convert<TFrom, TTo>(TFrom fromValue)
{
// Creating a parameter expression
ParameterExpression fromExpression = Expression.Parameter(typeof(TFrom), "from");
// Creating a parameter express
ParameterExpression toExpression = Expression.Parameter(typeof(TTo), "to");
// Creating a method body
BlockExpression blockExpression = Expression.Block(
new[] { toExpression },
Expression.Assign(toExpression, fromExpression)
);
return Expression.Lambda<Func<TFrom, TTo>>(blockExpression, fromExpression).Compile()(fromValue);
}
}
}