using System; using LanLib.UpdateManager.Extensions; namespace LanLib.UpdateManager.Jobs { /// /// Add this to a managed job struct type for declaring dependencies between managed update jobs. /// /// /// Dependency types must be struct types that implement either or . /// [AttributeUsage(AttributeTargets.Struct)] public class DependsOnAttribute : Attribute { public Type[] DependencyTypes { get; private set; } public DependsOnAttribute(params Type[] dependencyTypes) { AssertUpdateJobTypes(dependencyTypes); DependencyTypes = dependencyTypes; } public static void AssertUpdateJobTypes(params Type[] dependencyTypes) { foreach (Type type in dependencyTypes) { if (!type.IsValueType) { throw new ArgumentException( $"Dependency type must be a struct type: '{type}'", nameof(dependencyTypes) ); } if (!type.IsIUpdateJob() && !type.IsIUpdateTransformJob()) { throw new ArgumentException( $"Dependency type must implement IUpdateJob or IUpdateTransformJob: '{type}'", nameof(dependencyTypes) ); } } } } }