I have a generic method and I want to send to it a type taken from a string variable.
The signature of my generic method is:
public ICollection<TEntity> agregarItems<TEntity>(ComboBox cb) where TEntity : new()
And I want to do this:
Type tipo = Type.GetType("MyNamespace." + cb.Name);
cliente.GetType().GetProperty(cb.Name).SetValue(cliente,
agregarItems<tipo>(cb), null);
Where cb is a ComboBox object and cliente is an instance of a class.
cb.Name could be "Phone" and the Phone class already exists in MyNamespace.
Because tipo isn't defined formally I get the following error:
The type or namespace name 'tipo' could not be found (are you missing a using directive or an assembly reference?)
I need a workaround that let me send a not formally defined type to the generic method.