Any reason why concrete type inheriting from a generic type implementing IEnumerable is not supported?
Posted: Fri Aug 05, 2022 4:24 am
Considering this code, any way to work around the limitation that generic base type implementing IEnumerable is not allowed but is generic base not implementing IEnumerable is allowed?
Code: Select all
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaveTest : MonoBehaviour
{
void Start()
{
var list = new ConcreteList();
ES3.Save("save", list);
var list2 = ES3.Load("save", new ConcreteList());
list2.Print();
}
}
[Serializable]
public class ConcreteType
{
public string name = "test";
}
[Serializable]
public class ThisWorkList<T>
{
[SerializeField] protected List<T> list = new();
public void Print() => Debug.Log(list.ToString());
}
[Serializable]
public class ThisDontWorkList<T> : IEnumerable<T>
{
[SerializeField] protected List<T> list = new();
public void Print() => Debug.Log(list.ToString());
public IEnumerator<T> GetEnumerator() => list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator();
}
[Serializable]
public class ConcreteList : ThisDontWorkList<ConcreteType>
{
}