In my C# application, I have the need to create an instance of a Tuple. But here's the catch - I don't know the Tuple type in advance, only at runtime. If I have methods that can create instances of any types likely to be in the Tuple, then is there a way to use reflection to create such a Tuple instance? For example, I'm thinking along these lines, but I can't get it to work:
if (type typeof(Tuple))
{
FieldInfo[] fieldInfoArray = type.GetFields();
object[] = CreateArrayOfObjectsFromFieldInfoArray(fieldInfoArray);
return new Tuple(objectArray);
}
Is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire