KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Looks like ExpressionTrees compiler should be near with the C# spec in many behaviors, but unlike C# there is no support for conversion from decimal to any enum-type : using System; using System.Linq.Expressions; class Program { static void Main() { Func<decimal, ConsoleColor> converter1 = x => (ConsoleColor) x; ConsoleColor c1 = converter1(7m); // fine Expression<Func<decimal, ConsoleColor>> expr = x => (ConsoleColor) x; // System.InvalidOperationException was unhandled // No coercion operator is defined between types // 'System.Decimal' and 'System.ConsoleColor'. Func<decimal, ConsoleColor> converter2 = expr.Compile(); ConsoleColor c2 = converter2(7m); } } Other rarely used C# explicit conversions, like double -> enum-type exists and works as explained in C# specification, but not decimal -> enum-type . Is this a bug?
Tags (comma-separated)
Save Edits
Cancel