✅ Type Casting
Hi,
Just wondering how I would type cast the object 'control' to the type 'telerikslider'?
12 Replies
var foo = (TelerikSlider<>)control;
you'd want the variable to be initialized outside of the foreach thoughuse pattern matching
ish
i had no idea you could do this
this is excellent
don't monkaS me 😛
Thanks for the help. Learned 2 different ways. Even better!
Won't work for a generic without a type
As in the pattern matching method?
You can get a Type object with typeof without a generic but if you want to cast in any way, you need the generic
Not sure even
== typeof(TelerikSlider<>)
would work as no object can be of that type
You need the type that goes in <>, unless there's a base TelerikSlider typeThat's what ultimately led me to here as every example is with a generic
Check the metadata or docs to see if it derives from TelerikSlider and if so, use that
If not, you'll need to make the context itself generic and use T in TelerikSlider
In that latter scenario, the caller is responsible of providing the generic type
Though not sure if you can do that in cshtml
Turns out it needed an argument in the angle brackets of the type. Question now is, how do I store/save the value to the SavedValue field in the UserSetting class?
Yes, that's the generic type
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.