forked from ServiceStackV3/ServiceStack.Contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceOperations.cs
More file actions
67 lines (59 loc) · 2.06 KB
/
ServiceOperations.cs
File metadata and controls
67 lines (59 loc) · 2.06 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace ServiceStack.WebHost.Endpoints.Metadata
{
public class ServiceOperations
{
IDictionary<string, Type> OperationTypesMap { get; set; }
public ServiceOperations(IList<Type> dtoTypes)
{
AllOperations = new Operations(dtoTypes);
ReplyOperations = AllOperations.ReplyOperations;
OneWayOperations = AllOperations.OneWayOperations;
LoadOperationTypes(dtoTypes);
}
/// <summary>
/// Gets the name of the base most type in the heirachy tree with the same.
///
/// We get an exception when trying to create a schema with multiple types of the same name
/// like when inheriting from a DataContract with the same name.
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static Type GetBaseTypeWithTheSameName(Type type)
{
var typesWithSameName = new Stack<Type>();
var baseType = type;
do
{
if (baseType.Name == type.Name)
typesWithSameName.Push(baseType);
}
while ((baseType = baseType.BaseType) != null);
return typesWithSameName.Pop();
}
/// <summary>
/// Loads the operation types into a dictionary.
/// If there are multiple operation types with the same name,
/// the operation type that is last will be the one 'discoverable' via the service.
/// </summary>
/// <param name="operationTypes">The operation types.</param>
private void LoadOperationTypes(IEnumerable<Type> operationTypes)
{
OperationTypesMap = new Dictionary<string, Type>();
foreach (var operationType in operationTypes)
{
OperationTypesMap[operationType.Name] = operationType;
}
}
public Type GetOperationType(string operationTypeName)
{
return OperationTypesMap.ContainsKey(operationTypeName) ? OperationTypesMap[operationTypeName] : null;
}
public Operations ReplyOperations { get; private set; }
public Operations OneWayOperations { get; private set; }
public Operations AllOperations { get; private set; }
}
}