encompass-cs/encompass-cs/Attributes/Sends.cs

28 lines
713 B
C#
Raw Normal View History

2019-07-19 01:20:38 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using Encompass.Exceptions;
namespace Encompass
{
[AttributeUsage(AttributeTargets.Class)]
public class Sends : Attribute
{
2020-03-20 07:09:57 +00:00
public readonly HashSet<Type> SendTypes;
2019-07-19 01:20:38 +00:00
public Sends(params Type[] sendTypes)
{
foreach (var sendType in sendTypes)
{
var isMessage = sendType.GetInterfaces().Contains(typeof(IMessage));
if (!isMessage)
{
2019-07-19 19:47:17 +00:00
throw new IllegalSendTypeException("{0} must be a Message", sendType.Name);
2019-07-19 01:20:38 +00:00
}
}
2020-03-20 07:09:57 +00:00
this.SendTypes = new HashSet<Type>(sendTypes);
2019-07-19 01:20:38 +00:00
}
}
}