C
C#2w ago
Thiagohaga

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).
No description
11 Replies
Thiagohaga
Thiagohaga2w ago
No description
Thiagohaga
Thiagohaga2w ago
'targetType' is not null here. CS0118 "targetType" is a variable but is used as a type.
Buddy
Buddy2w ago
Use generics
Thiagohaga
Thiagohaga2w ago
Tried, says its not valid
Buddy
Buddy2w ago
I mean Input<T>(..)
Thiagohaga
Thiagohaga2w ago
yes that look
Thiagohaga
Thiagohaga2w ago
No description
Thiagohaga
Thiagohaga2w ago
T is a type that is not valid in this context
No description
Buddy
Buddy2w ago
Use a generic constraint on that And use T.TryParse(..) And ignore TypeDescriptor
Thiagohaga
Thiagohaga2w ago
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