using System; using System.Diagnostics; using System.Linq.Expressions; namespace SampleConsoleApp1 { static class StaticCast { private static Func cast = GenerateCast(); private static Func GenerateCast() { var param = Expression.Parameter(typeof(TSource)); var convert = Expression.Convert(param, typeof(TDestination)); var lambda = Expression.Lambda>(convert, param); return lambda.Compile(); } public static TDestination Apply(TSource value) { return cast(value); } } class NumUpDownEx { public decimal m_ud_value; public T Value { get { return StaticCast.Apply(m_ud_value); } } } class Program { static void Main(string[] args) { var obj1 = new NumUpDownEx(); obj1.m_ud_value = 1234m; Console.WriteLine(1234 == obj1.Value); var obj2 = new NumUpDownEx(); obj2.m_ud_value = 3456.7m; Console.WriteLine((double)3456.7m == obj2.Value); } } }