Given the string "string[]"
and asked to get the underlying Type for this class, one might start with:
private Type getTypeByName(string typeName)
{
if (typeName.EndsWith("[]"))
{
return something; // But what?
}
return Type.GetType(typeName);
}
What type is "string[]" and how does one reflect the type out of it?
Obviously there's a System.String
type and a System.Array
type, but I can't see how they can be reflected "together" as you would normally do for Nullable<T>
and its T with the MakeGenericType
method.
Any help to break the mind-loop I've gotten myself into will be greatly appreciated!
Use GetElementType() on the type:
ttt is of type String.
What exactly is your problem?
Type.GetType
works fine:Prints:
so clearly this works as expected.
Type.GetType("System.String[]") will returns the string array type. No need to check for [] in your input string.
You can verity this by checking the Type.IsArray prop.
The type is System.String[]