Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a non-generic Il2CppArrayBase class #126

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading