C
C#5mo 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
ThiagohagaOP5mo ago
No description
Thiagohaga
ThiagohagaOP5mo ago
'targetType' is not null here. CS0118 "targetType" is a variable but is used as a type.
Buddy
Buddy5mo ago
Use generics
Thiagohaga
ThiagohagaOP5mo ago
Tried, says its not valid
Buddy
Buddy5mo ago
I mean Input<T>(..)
Thiagohaga
ThiagohagaOP5mo ago
yes that look
Thiagohaga
ThiagohagaOP5mo ago
No description
Thiagohaga
ThiagohagaOP5mo ago
T is a type that is not valid in this context
No description
Buddy
Buddy5mo ago
Use a generic constraint on that And use T.TryParse(..) And ignore TypeDescriptor
Thiagohaga
ThiagohagaOP5mo 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
Want results from more Discord servers?
Add your server