Hi everyone,
I haven't actually tried .NET 4.0 yet, but I'm wondering if something like the following code might be allowed by the C# compiler in 4.0 using
dynamic and DLR overload resolution:
private void GetAndDisplayEmployee(string id)
{
DisplayResult(
GetEmployee(id) ?? "Uh oh, bad id!"
);
}
private void DisplayResult(Employee employee)
{
// TODO: Display employee
}
private void DisplayResult(string message)
{
// TODO: Display message
}
It seems that I often find myself in situations like these where use of the null-coalescing operator would be really slick, but a coercion requirement prevents it. I guess the solution would be for the null-coalescing operator to return
dynamic in these situations?
- Dave
http://davesexton.com/blog