forked from scriptcs-contrib/scriptcs-webapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerResolver.cs
More file actions
42 lines (33 loc) · 1.3 KB
/
Copy pathControllerResolver.cs
File metadata and controls
42 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
namespace ScriptCs.WebApi
{
internal class ControllerResolver : DefaultHttpControllerTypeResolver
{
private ICollection<Type> _controllerTypes;
internal ControllerResolver(ICollection<Type> controllerTypes)
{
Contract.Requires(AllAssignableToIHttpController(controllerTypes));
_controllerTypes = controllerTypes;
}
public override ICollection<Type> GetControllerTypes(IAssembliesResolver assembliesResolver)
{
Contract.Invariant(_controllerTypes != null);
return _controllerTypes;
}
internal static IEnumerable<Type> WhereControllerType(IEnumerable<Type> types)
{
Contract.Requires(types != null);
return types.Where(x => typeof(IHttpController).IsAssignableFrom(x) && x != typeof(IHttpController));
}
internal static bool AllAssignableToIHttpController(IEnumerable<Type> types)
{
Contract.Requires(types != null);
return types.All(x => typeof(IHttpController).IsAssignableFrom(x));
}
}
}