using System.Dynamic; namespace DTLib.Dtsod.V24.Autoarr; using AutoarrPtr=System.IntPtr; public abstract class AutoarrFunctions { internal abstract AutoarrPtr Create(ushort maxBlocksCount, ushort maxBlockLength); internal abstract void Free(AutoarrPtr ar); internal abstract T Get(AutoarrPtr ar, uint index); internal abstract void Add(AutoarrPtr ar, T element); internal abstract void Set(AutoarrPtr ar, uint index, T element); internal abstract uint Length(AutoarrPtr ar); internal abstract uint MaxLength(AutoarrPtr ar); private static AutoarrFunctions f_uni = new AutoarrUnitypeFunctions(); private static AutoarrFunctions f_kvp = new AutoarrKVPairFunctions(); static internal AutoarrFunctions GetFunctions() { if (typeof(T) == typeof(Unitype)) return (AutoarrFunctions)Convert.ChangeType(f_uni, typeof(AutoarrFunctions)); else if (typeof(T) == typeof(KVPair)) return (AutoarrFunctions) Convert.ChangeType(f_kvp, typeof(AutoarrFunctions)); else throw new Exception($"unsupported type: {typeof(T)}"); } }