vb.net - How to let .NET know that I have an instance of the right class? -


let's suppose have a

class viewermanager(of viewtable) 

and inside have a

protected readonly property storedview viewtable 

which has get inside have this

#region "view object properties"      enum viewermanagertemplate         unkown = 1         tblmemorizedfilterpage = 2         tblmemorizedaev = 3     end enum      protected _managertemplate viewermanagertemplate = viewermanagertemplate.unkown     protected readonly property managertemplate viewermanagertemplate                     if _managertemplate = viewermanagertemplate.unkown                 if pageid > 0                     _managertemplate = viewermanagertemplate.tblmemorizedfilterpage                 else                     _managertemplate = viewermanagertemplate.tblmemorizedaev                 end if             end if             return _managertemplate         end     end property      protected initializedstoredview boolean = false     protected _storedview viewtable = nothing     protected readonly property storedview viewtable                     if not initializedstoredview                 initializedstoredview = true                 select case managertemplate                     case viewermanagertemplate.tblmemorizedfilterpage                         if pageobject.storedviewid > 0                             _storedview = ctype(ctype(bos.customgridbo.getmemorizedfilterpage(pageobject.storedviewid), object), viewtable)                         end if                 end select             end if             return _storedview         end     end property #end region 

here, @ line of

_storedview = ctype(ctype(bos.customgridbo.getmemorizedfilterpage(pageobject.storedviewid), object), viewtable) 

i know sure bos.customgridbo.getmemorizedfilterpage return tblmemorizedfilterpage instance , know sure if line executed, viewtable tblmemorizedfilterpage well, therefore double ctype seems overkill me. can simplify somehow?

edit:

since there confusion in comment section, think need give further information. tblmemorizedfilterpage , tblmemorizedaev both classes , enum values having same name named after these classes.

you have no choice, when viewtable tblmemorizedaev. line like.

_storedview = ctype(ctype(bos.customgridbo.getmemorizedfilterpage(pageobject.storedviewid), object), tblmemorizedaev) 

since can't cast tblmemorizedfilterpage tblmemorizedaev. option trick compiler casting object first. base class in common each other.

if have lot of if statement, think of having 2 classes class viewermanager(of viewtable) base class. sub class handle specific situation.

i find strange template type dependent on enum enum isn't based on template type. viewermanager(of tblmemorizedaev) , pageid greater 0.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -