Issue 1075: Web API: Improve resolution of ApiController types.

GetExportedTypes() has a different behavior as compared to GetTypes().
GetExportedTypes() throws a FileNotFoundException if it is unable to load
dependent assemblies where as GetTypes() throws
ReflectionTypeLoadException containing loaded types.
This commit is contained in:
raghuramn 2013-07-30 19:34:46 -07:00
Родитель 36fe807d5a
Коммит 8fc982e386
4 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -177,7 +177,7 @@ namespace System.Web.Http
try
{
exportedTypes = assembly.GetExportedTypes();
exportedTypes = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
@ -190,7 +190,7 @@ namespace System.Web.Http
if (exportedTypes != null)
{
result.AddRange(exportedTypes.Where(t => t != null));
result.AddRange(exportedTypes.Where(t => t != null && t.IsVisible));
}
}

Просмотреть файл

@ -83,7 +83,7 @@ namespace System.Web.Http.Dispatcher
try
{
exportedTypes = assembly.GetExportedTypes();
exportedTypes = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
@ -100,7 +100,7 @@ namespace System.Web.Http.Dispatcher
if (exportedTypes != null)
{
result.AddRange(exportedTypes.Where(x => IsControllerTypePredicate(x)));
result.AddRange(exportedTypes.Where(x => TypeIsVisible(x) && IsControllerTypePredicate(x)));
}
}
@ -118,5 +118,10 @@ namespace System.Web.Http.Dispatcher
string controllerSuffix = DefaultHttpControllerSelector.ControllerSuffix;
return controllerType.Name.Length > controllerSuffix.Length && controllerType.Name.EndsWith(controllerSuffix, StringComparison.OrdinalIgnoreCase);
}
private static bool TypeIsVisible(Type type)
{
return (type != null && type.IsVisible);
}
}
}

Просмотреть файл

@ -23,7 +23,7 @@ namespace System.Web.Http.OData
_types = types.Select(t => t.Object).ToArray();
}
public override Type[] GetExportedTypes()
public override Type[] GetTypes()
{
return _types;
}

Просмотреть файл

@ -181,7 +181,7 @@ namespace System.Web.Http.Dispatcher
get { return false; }
}
public override Type[] GetExportedTypes()
public override Type[] GetTypes()
{
switch (_throwException)
{