How can I loop through and get generic class from a list in c#. My code is like this.
private void processList()
{
List<CommandParameter> parameters = new List<CommandParameter>();
parameters.Add(new CommandParameter<string>("a", "c", "a"));
parameters.Add(new CommandParameter<int>("a", "c", 1));
foreach (var parameter in parameters)
{
// How can I loop through the parameters list and get the generic class
}
}
Is this possible? Can anyone tell me how to solve this?
this is command parameter classes
public class CommandParameter<T> : CommandParameter{
public string Str { get; private set; }
public string TypeName { get;private set; }
public T TypeValue { get; private set; }
public CommandParameter(string s, string typeName, T typeValue) {
Str = s;
TypeName = typeName;
TypeValue = typeValue;
}
}
public abstract class CommandParameter {
}
commandParameter<string>andcommandParameter<int>from the list in the loopparameter.GetType(), presumably.Type t = parameter.GetType()right? but then how can i access the fields? do i have to use reflection?