Creating the input from Python
I was trying to create something similar to input from python, just to have fun, but I came across the problem that I dont understand how Type datatype works.
I need help on making the get converter work depending on the type I wish to get, and also set the default type to something similar to (Type targetType = string).
11 Replies
'targetType' is not null here.
CS0118 "targetType" is a variable but is used as a type.
Use generics
Tried, says its not valid
I mean
Input<T>(..)
yes that
look
IParsable Interface (System)
Defines a mechanism for parsing a string to a value.
T is a type that is not valid in this context
Use a generic constraint on that
And use
T.TryParse(..)
And ignore TypeDescriptor
Not possible, even tho that function probably exists
because it cant member search inside the generic type
Thats why I used that weird one, but I failed miserably
being type safe is truly a hellish thing
Btw this was solved, I just used the (T)Convert.ChangeType