2019-06-16 01:55:35 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2019-07-16 18:17:07 +00:00
|
|
|
using System.Linq;
|
|
|
|
using Encompass.Exceptions;
|
2019-06-16 01:55:35 +00:00
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
{
|
2019-07-18 21:02:57 +00:00
|
|
|
[AttributeUsage(AttributeTargets.Class)]
|
|
|
|
public class Reads : Attribute
|
2019-06-16 01:55:35 +00:00
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
public readonly HashSet<Type> ReadTypes = new HashSet<Type>();
|
2019-06-16 01:55:35 +00:00
|
|
|
|
2019-07-16 18:17:07 +00:00
|
|
|
public Reads(params Type[] readTypes)
|
2019-06-16 01:55:35 +00:00
|
|
|
{
|
2019-07-16 18:17:07 +00:00
|
|
|
foreach (var readType in readTypes)
|
|
|
|
{
|
2019-07-18 21:02:57 +00:00
|
|
|
var isComponent = readType.GetInterfaces().Contains(typeof(IComponent));
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
if (!isComponent)
|
2019-07-16 18:17:07 +00:00
|
|
|
{
|
2019-07-19 19:47:17 +00:00
|
|
|
throw new IllegalReadTypeException("{0} must be a Component", readType.Name);
|
2019-07-16 18:17:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
this.ReadTypes.Add(readType);
|
2019-07-18 21:02:57 +00:00
|
|
|
}
|
2019-06-16 01:55:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|