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