using System; using System.Reflection; using LanLib.UpdateManager.Extensions; namespace LanLib.UpdateManager.Jobs.Internal { public static class UpdateJobOptions { public const int DefaultBatchSize = 64; public static int GetBatchSize() { if (typeof(TData).GetCustomAttribute() is JobBatchSizeAttribute batchSizeAttribute) { return batchSizeAttribute.BatchSize; } #pragma warning disable CS0618 else if (typeof(TData).GetCustomAttribute() is UpdateJobOptionsAttribute options && options.BatchSize > 0) { return options.BatchSize; } #pragma warning restore CS0618 else { return DefaultBatchSize; } } public static bool GetReadOnlyTransformAccess() { return typeof(TData).GetCustomAttribute() != null #pragma warning disable CS0618 || (typeof(TData).GetCustomAttribute() is UpdateJobOptionsAttribute options && options.ReadOnlyTransforms); #pragma warning restore CS0618 } public static Type[] GetDependsOn() { if (typeof(TData).GetCustomAttribute() is DependsOnAttribute dependsOn && dependsOn.DependencyTypes?.Length > 0) { return dependsOn.DependencyTypes; } else { return Array.Empty(); } } public static IJobManager[] GetDependsOnManagers() { Type[] dependencyTypes = GetDependsOn(); if (dependencyTypes.Length == 0) { return Array.Empty(); } var managers = new IJobManager[dependencyTypes.Length]; for (int i = 0; i < dependencyTypes.Length; i++) { Type type = dependencyTypes[i]; if (type.IsIUpdateJob()) { managers[i] = (IJobManager) typeof(UpdateJobManager<>).MakeGenericType(type).GetProperty("Instance").GetValue(null); } else if (type.IsIUpdateTransformJob()) { managers[i] = (IJobManager) typeof(UpdateTransformJobManager<>).MakeGenericType(type).GetProperty("Instance").GetValue(null); } else { throw new ArgumentException( $"Dependency type '{type}' must implement IUpdateJob or IUpdateTransformJob", nameof(DependsOnAttribute.DependencyTypes) ); } } return managers; } #if HAVE_BURST public static bool GetIsBurstCompiled() { return typeof(TData).ImplementsGenericInterface(typeof(IBurstUpdateJob<>)) || typeof(TData).ImplementsGenericInterface(typeof(IBurstUpdateTransformJob<>)); } #endif } }