I thought I had a pretty good grasp of the difference between the is
keyword and the IsAssignableFrom
method, but researching SubControllers in MVC I ran across some code that made me think maybe there's something I'm missing. Here it is:
object value = pair.Value;
if(value == null)
{
continue;
}
if (typeof(ISubController).IsAssignableFrom(value.GetType()))
{
var controller = (ISubController) value;
filterContext.Controller.ViewData.Add(pair.Key, controller.GetResult(filterContext.Controller));
}
That second if
statement looks to me like a convoluted version of:
if (value is ISubController)
Also, I had previously learned that typeof(T).IsValueType
takes about three times as long as x is ValueType
, so I don't think they're getting any performance advantage out of this added complication.
Is there some nuance that I'm missing here? I'd like to think the ASP.NET MVC guys know what they're doing.