Convert switch statements to switch on type

Issue #50 new
Tyler Reynolds created an issue

It's a minor thing, but could maybe help with clarity going forward. I'll take care of it if it's something that could be beneficial.

The current code looks like this:

switch (u.GetType().ToString())
{
    case "System.Windows.Controls.Slider":
    Slider s = u as Slider;
    s.Value = (double) o;
    ...
}

I propose:

switch (u.GetType())
{
    case System.Windows.Controls.Slider s;
    s.Value = (double) o;
    ...
}

It would save a line per case (trivial, I know), but I would think it's better to match by type than type converted to string.

Comments (1)

  1. Log in to comment