.net - How to Convert this generic method from C# to VB.Net -
i have following code block in c#
private void synchronize<t>(textselection selection, dependencyproperty property, action<t> methodtocall) { object value = selection. getpropertyvalue(property) ; if ( value != dependencyproperty. unsetvalue) methodtocall((t) value) ; }
that have converted vb.
private sub synchronize(of t)(byval selection textselection, byval [property] dependencyproperty, byval methodtocall action(of t)) dim value object = selection.getpropertyvalue([property]) if value isnot dependencyproperty.unsetvalue methodtocall(directcast(value, t)) end if end sub
the calling method like:
synchronize(of double)(selection, textblock.fontsizeproperty, addressof setfontsize) synchronize(of fontweight)(selection, textblock.fontsizeproperty, addressof setfontweight) synchronize(of fontstyle)(selection, textblock.fontstyleproperty, addressof setfontstyle) synchronize(of fontfamily)(selection, textblock.fontfamilyproperty, addressof setfontfamily) synchronize(of textdecorationcollection)(selection, textblock.textdecorationsproperty, addressof settextdecoration)
my problem directcast call; if delegate argument can simple type (integer, double, etc) or object. directcast doesn't simple data types invalidcastexception thrown when try cast double. have suggested solution problem? i've tried trycast, doesn't (of t) , says must class contstrained.
thanks all!
ryan
try ctype() instead of directcast().
Comments
Post a Comment