Premise is for a development in Unity3D with C #
I have a serialized class called Tool.
namespace Game.Data{
[Serializable]
public sealed class Tool
{
public int id;
public string name;
}
}
From another class I have created a method to add to a list, see below.
// type == nombre de la lista genérica
// data == Tool
public void Add( string type , object data )
{
// var insert = dictionary[type] as List<Tool>
var insert = dictionary [type] as IList;
insert.Add (data);
}
Execution of the previous script.
Tool item = new Tool();
item.id = 0;
item.name = "sierra";
Add( "Tool" , item );
dictionary [type] is a object that can become a List Tool >, but I discovered that with IList I do not need to implement the generic variable List < T > - It's great because I can automate my list - and execute the Add method;
My goal is to create an interface or to somehow make the Find, FindAll, ForEach methods of List < T > in iList.
Attached to the text is the method to create a dictionary with dynamic list.
public List<TypeItem> types; // Tipos de items
public List<Tool> tools
// Diccionario dinámico
Dictionary<string, object> dictionary;
void DynamicList()
{
dictionary = new Dictionary<string, object> ();
// Añadir listas al diccionario
dictionary.Add("Tool", tools);
dictionary.Add("Type", types);
}