protected override Expression <Func <TFrom, TTo, TTo> > CompileToExpression() { var allConversions = this.aConversions.ToList(); var from = Expression.Parameter(typeof(TFrom), "from"); var to = Expression.Parameter(typeof(TTo), "to"); return(Expression.Lambda <Func <TFrom, TTo, TTo> >( Expression.Block( Expression.Switch( typeof(void), Expression.Call(from, ObjectMethods.GetType()), Expression.Throw( Expression.New( typeof(UnknownMappingException).GetConstructor(new Type[] { typeof(Type), typeof(Type) }), Expression.Call(from, ObjectMethods.GetType()), Expression.Constant(typeof(TTo)) ) ), null, allConversions.Select(x => this.MakeIfConvertSynchronizeStatement(x.From, x.To, x.Mapping.ResolvedMapping, from, to)) ), to ), from, to )); }