2019-08-21 02:25:59 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using Encompass.Exceptions;
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
{
|
|
|
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
|
|
|
public class Writes : Attribute
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
public readonly HashSet<Type> WriteTypes = new HashSet<Type>();
|
|
|
|
public readonly Dictionary<Type, int> Priorities = new Dictionary<Type, int>();
|
2019-08-21 02:25:59 +00:00
|
|
|
|
|
|
|
public Writes(params Type[] writeTypes)
|
|
|
|
{
|
|
|
|
foreach (var writeType in writeTypes)
|
|
|
|
{
|
|
|
|
var isComponent = writeType.GetInterfaces().Contains(typeof(IComponent));
|
|
|
|
if (!isComponent)
|
|
|
|
{
|
|
|
|
throw new IllegalWriteTypeException("{0} must be a Component", writeType.Name);
|
|
|
|
}
|
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
this.WriteTypes.Add(writeType);
|
2019-08-21 02:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Writes(Type writeType, int priority)
|
|
|
|
{
|
|
|
|
var isComponent = writeType.GetInterfaces().Contains(typeof(IComponent));
|
|
|
|
if (!isComponent)
|
|
|
|
{
|
|
|
|
throw new IllegalWriteTypeException("{0} must be a Component", writeType.Name);
|
|
|
|
}
|
|
|
|
|
2020-03-20 07:09:57 +00:00
|
|
|
WriteTypes.Add(writeType);
|
|
|
|
Priorities.Add(writeType, priority);
|
2019-08-21 02:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-26 20:26:48 +00:00
|
|
|
}
|