Skip to content

Commit

Permalink
Create a nongeneric Il2CppArrayBase class
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Jun 29, 2024
1 parent 45e22c2 commit 1262b53
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Il2CppInterop.Runtime/InteropTypes/Arrays/Il2CppArrayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@

namespace Il2CppInterop.Runtime.InteropTypes.Arrays;

public abstract class Il2CppArrayBase<T> : Il2CppObjectBase, IList<T>
public abstract class Il2CppArrayBase : Il2CppObjectBase, IEnumerable
{
protected Il2CppArrayBase(IntPtr pointer) : base(pointer)
{
}

public int Length => (int)IL2CPP.il2cpp_array_length(Pointer);

IEnumerator IEnumerable.GetEnumerator()
public abstract IEnumerator GetEnumerator();

private protected static bool ThrowImmutableLength()
{
throw new NotSupportedException("Arrays have immutable length");
}
}
public abstract class Il2CppArrayBase<T> : Il2CppArrayBase, IList<T>, IReadOnlyList<T>
{
protected Il2CppArrayBase(IntPtr pointer) : base(pointer)
{
return GetEnumerator();
}

public IEnumerator<T> GetEnumerator()
public sealed override IEnumerator<T> GetEnumerator()
{
return new IndexEnumerator(this);
}
Expand Down Expand Up @@ -54,8 +62,9 @@ bool ICollection<T>.Remove(T item)
return ThrowImmutableLength();
}

public new int Length => base.Length;// For binary compatibility
public int Count => Length;
public bool IsReadOnly => false;
bool ICollection<T>.IsReadOnly => false;

public int IndexOf(T item)
{
Expand Down Expand Up @@ -93,11 +102,6 @@ protected static void StaticCtorBody(Type ownType)
Il2CppClassPointerStore<Il2CppArrayBase<T>>.CreatedTypeRedirect = ownType;
}

private static bool ThrowImmutableLength()
{
throw new NotSupportedException("Arrays have immutable length");
}

public static implicit operator T[](Il2CppArrayBase<T> il2CppArray)
{
if (il2CppArray == null)
Expand Down

0 comments on commit 1262b53

Please sign in to comment.