using Svelto.ECS.Reference; namespace Svelto.ECS.Internal { delegate void SetEGIDWithoutBoxingActionCast(ref T target, EGID egid) where T : struct, IEntityComponent; delegate void SetReferenceWithoutBoxingActionCast(ref T target, EntityReference egid) where T : struct, IEntityComponent; static class SetEGIDWithoutBoxing where T : struct, IEntityComponent { public static readonly SetEGIDWithoutBoxingActionCast SetIDWithoutBoxing = MakeSetter(); public static readonly SetReferenceWithoutBoxingActionCast SetRefWithoutBoxing = MakeSetterReference(); public static void Warmup() { } static SetEGIDWithoutBoxingActionCast MakeSetter() { if (ComponentBuilder.HAS_EGID) { #if !ENABLE_IL2CPP var method = typeof(Trick).GetMethod(nameof(Trick.SetEGIDImpl)).MakeGenericMethod(typeof(T)); return (SetEGIDWithoutBoxingActionCast) System.Delegate.CreateDelegate( typeof(SetEGIDWithoutBoxingActionCast), method); #else return (ref T target, EGID egid) => { var needEgid = (target as INeedEGID); needEgid.ID = egid; target = (T) needEgid; }; #endif } return null; } static SetReferenceWithoutBoxingActionCast MakeSetterReference() { if (ComponentBuilder.HAS_REFERENCE) { #if !ENABLE_IL2CPP var method = typeof(Trick).GetMethod(nameof(Trick.SetEGIDImplRef)).MakeGenericMethod(typeof(T)); return (SetReferenceWithoutBoxingActionCast) System.Delegate.CreateDelegate( typeof(SetReferenceWithoutBoxingActionCast), method); #else return (ref T target, EntityReference reference) => { var needEgid = (target as INeedEntityReference); needEgid.selfReference = reference; target = (T) needEgid; }; #endif } return null; } static class Trick { public static void SetEGIDImpl(ref U target, EGID egid) where U : struct, INeedEGID { target.ID = egid; } public static void SetEGIDImplRef(ref U target, EntityReference reference) where U : struct, INeedEntityReference { target.selfReference = reference; } } } }