avoid use of typeOf to known a class from a base class variable


Author
Message
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
How can I avoid to use typeOf when I have some classes that inherit from a base class and I have to compare what type of class the variable is



in the following code:



If TypeOf MainView Is Dx.DxGridView Then

With CType(MainView, Dx.DxGridView)

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With

ElseIf TypeOf MainView Is Dx.DxCardView Then 'DevExpress.XtraGrid.Views.Grid.GridView Then

With CType(MainView, Dx.DxCardView)

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With

End If





to something like:

With CType(MainView, ThetypeOf(MainView))

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With



MainView is a generic Class (devExpress BaseView) and I want to set a column property, but the generic class don't have a "column" and I have to use a ctype, I like to use a ctype (or something else) on the same object to know his type

I say, if mainview is a "cardview" or "gridView" when I put ctype(mainview,somefunctionthatgivemethetype(mainview).column work



the same to use with ctype(businesslayerVariable,getmyowntype(businesslayerVariable)).someproperty and ctype(businesslayerVariable,getmyowntype(businesslayerVariable)) give me myBO type



it is posible? thanks!



sorry if I cannot write my question correctly, I speak in spanish and it's hard to me Ermm
Reply
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)StrataFrame User (317 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Thanks for the fastest reply Smile



I try to use a inherited devexpress gridcontrol, and It have a mainview property that have the current visible view, I don't known if it are a cardview or gridview, but both of them have columns, I actually see what type is it with typeof, and then use ctype(mainview,<>).column = xxxxx



I'm reading about it and it appears to be called upcast? I have a variable of type "base" with the content of object "derived" and like to access a property "someproperty" of "derived"

if I put "base.someproperty" it doesn't exist, but .net dont allow me to use ctype(base,realtypeofbase(base)).someproperty and it is annoying (and not useful) to use and "if" or "select" all the time to compare the actual content of a base variable to see what derived object it have and use his properties....



actually I don't have control on MainView (I not sure if I can witout recompile the devexpress xtragrid source code), I will see if I can to use your aproach if I can edit BaseView (or derive it or something else), otherwise will try to use a generic (method?) that retrieve the type or something weird and out of my actual knowledge of .net w00t



thanks for all the help
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search