using System.Runtime.CompilerServices; namespace Svelto.ECS.Internal { delegate void SetEGIDWithoutBoxingActionCast(ref T target, EGID egid) where T : struct, IEntityComponent; static class SetEGIDWithoutBoxing where T : struct, IEntityComponent { public static readonly SetEGIDWithoutBoxingActionCast SetIDWithoutBoxing = MakeSetter(); 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 class Trick { public static void SetEGIDImpl(ref U target, EGID egid) where U : struct, INeedEGID { target.ID = egid; } } } }