Blame view

SoapCore/ServiceModel/ServiceDescription.cs 961 Bytes
gy.huang authored
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.ServiceModel;

namespace SoapCore.ServiceModel
{
	public class ServiceDescription
	{
		public ServiceDescription(Type serviceType)
		{
			ServiceType = serviceType;

			var types = Enumerable.Empty<Type>().Concat(ServiceType.GetInterfaces());
			types = types.Concat(new[] { ServiceType });

			var contracts = new List<ContractDescription>();
			foreach (var contractType in types)
			{
				foreach (var serviceContract in contractType.GetTypeInfo().GetCustomAttributes<ServiceContractAttribute>())
				{
					contracts.Add(new ContractDescription(this, contractType, serviceContract));
				}
			}

			Contracts = contracts;
		}

		public Type ServiceType { get; private set; }
		public IEnumerable<ContractDescription> Contracts { get; private set; }
		public IEnumerable<OperationDescription> Operations => Contracts.SelectMany(c => c.Operations);
	}
}