38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System;
|
|
|
|
namespace AlicizaX
|
|
{
|
|
internal static class ServiceContractUtility
|
|
{
|
|
public static ServiceContracts Create(Type serviceType)
|
|
=> new ServiceContracts(serviceType, null);
|
|
|
|
public static ServiceContracts Create(Type serviceType, Type contractType)
|
|
=> new ServiceContracts(serviceType, contractType);
|
|
}
|
|
|
|
internal readonly struct ServiceContracts
|
|
{
|
|
private readonly Type _serviceType;
|
|
private readonly Type _contractType;
|
|
|
|
public ServiceContracts(Type serviceType, Type contractType)
|
|
{
|
|
_serviceType = serviceType;
|
|
_contractType = contractType;
|
|
}
|
|
|
|
public int Count => _contractType == null || _contractType == _serviceType ? 1 : 2;
|
|
|
|
public Type this[int index]
|
|
{
|
|
get
|
|
{
|
|
if (index == 0) return _serviceType;
|
|
if (index == 1 && Count == 2) return _contractType;
|
|
throw new IndexOutOfRangeException();
|
|
}
|
|
}
|
|
}
|
|
}
|