using System; using System.Linq.Expressions; namespace MonoGame.Extended.Tweening { public abstract class TweenMember { protected TweenMember(object target) { Target = target; } public object Target { get; } public abstract Type Type { get; } public abstract string Name { get; } } public abstract class TweenMember : TweenMember where T : struct { static TweenMember() { var a = Expression.Parameter(typeof(T)); var b = Expression.Parameter(typeof(T)); var c = Expression.Parameter(typeof(float)); Add = Expression.Lambda>(Expression.Add(a, b), a, b).Compile(); Subtract = Expression.Lambda>(Expression.Subtract(a, b), a, b).Compile(); Multiply = Expression.Lambda>(Expression.Multiply(a, c), a, c).Compile(); } public static Func Add { get; } public static Func Subtract { get; } public static Func Multiply { get; } protected TweenMember(object target, Func getMethod, Action setMethod) : base(target) { _getMethod = getMethod; _setMethod = setMethod; } private readonly Func _getMethod; private readonly Action _setMethod; public T Value { get { return (T) _getMethod(Target); } set { _setMethod(Target, value); } } } }