/// <inheritdoc /> protected override void InsertAt(ref IEnumerable collection, int collectionIndex, object memberValue) { int count = GetCollectionSize(collection); var values = Array.CreateInstance(MemberType, count); CopyToMethod.InvokeWithParameter(collection, values); ClearMethod.Invoke(collection); var add = AddMethod; for (int n = 0; n < collectionIndex; n++) { add.InvokeWithParameter(collection, values.GetValue(n)); } add.InvokeWithParameter(collection, memberValue); for (int n = collectionIndex; n < count; n++) { add.InvokeWithParameter(collection, values.GetValue(n)); } #if DEV_MODE Debug.Assert(GetCollectionSize(collection) == count + 1); #endif }
/// <inheritdoc /> protected override void SetCollectionValue(ref IEnumerable collection, int collectionIndex, object memberValue) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!ReadOnly); #endif int count = GetCollectionSize(collection); var values = Array.CreateInstance(MemberType, count); CopyToMethod.InvokeWithParameter(collection, values); ClearMethod.Invoke(collection); var add = AddMethod; for (int n = 0; n < collectionIndex; n++) { add.InvokeWithParameter(collection, values.GetValue(n)); } #if DEV_MODE && PI_ASSERTATIONS if (memberValue == null) { Debug.LogError("HashSet cannot contain null values!"); } else if (memberValue.GetType() != memberType) { Debug.LogError(Msg("SetCollectionValue called with memberValue ", memberValue, " with type ", memberValue.GetType(), " not matching memberType ", memberType)); } #endif add.InvokeWithParameter(collection, memberValue); for (int n = collectionIndex + 1; n < count; n++) { add.InvokeWithParameter(collection, values.GetValue(n)); } }
/// <inheritdoc /> protected override bool Sort(ref IEnumerable collection, IComparer comparer) { int count = GetCollectionSize(collection); var array = Array.CreateInstance(MemberType, count); CopyToMethod.InvokeWithParameters(collection, array, 0); Array.Sort(array, comparer); if (!array.ContentsMatch(collection)) { ClearMethod.Invoke(collection); for (int i = 0; i < count; i++) { AddMethod.InvokeWithParameter(collection, array.GetValue(i)); } return(true); } return(false); }