IsAssignableFrom или AS?

У меня есть следующий код:

private T CreateInstance<T>(object obj) // where T : ISomeInterface, class
{
    ...

    if (!typeof(T).IsAssignableFrom(obj.GetType())) { throw ..; }

    return (T)obj;
}

Может это быть замененным этим:

T result = obj as T;

if (result == null) { throw ..; }

return result;

Если не - почему?

5
задан abatishchev 3 August 2010 в 13:39
поделиться