com.alicizax.unity.framework/Runtime/ABase/Service/Core/ServiceContractUtility.cs

38 lines
1.0 KiB
C#
Raw Normal View History

2026-03-26 10:49:41 +08:00
using System;
namespace AlicizaX
{
internal static class ServiceContractUtility
{
public static ServiceContracts Create(Type serviceType)
=> new ServiceContracts(serviceType, null);
2026-03-26 10:49:41 +08:00
public static ServiceContracts Create(Type serviceType, Type contractType)
=> new ServiceContracts(serviceType, contractType);
}
2026-03-26 13:51:09 +08:00
internal readonly struct ServiceContracts
{
private readonly Type _serviceType;
private readonly Type _contractType;
2026-03-26 13:51:09 +08:00
public ServiceContracts(Type serviceType, Type contractType)
{
_serviceType = serviceType;
_contractType = contractType;
2026-03-26 13:51:09 +08:00
}
public int Count => _contractType == null || _contractType == _serviceType ? 1 : 2;
2026-03-26 10:49:41 +08:00
public Type this[int index]
{
get
2026-03-26 10:49:41 +08:00
{
if (index == 0) return _serviceType;
if (index == 1 && Count == 2) return _contractType;
throw new IndexOutOfRangeException();
2026-03-26 10:49:41 +08:00
}
}
}
}