.net - Cast Class Type at Runtime in VB.NET -


I have seen a lot of answers, and in fact I'm trying to achieve what I'm looking forward to.

I have a database with hundreds of views I use the dipper to ask the result of a scene. I present the results in the grid. This is a read-only operation. Visual results are already mapped to classes. Here is a specific query:

queryResults = conn.Query (of vw_EmployeeProductDetails) (queryString, Nothing)

Right now, I have a different query each View (each in their own function) I like to pass in a function in queryString and "ViewType" to get the results.

View Type = Due ViewType = GetType (vw_EmployeeProductDetails) SelectView (queryString, ViewType) in the usual query function: ... queryResults = conn.Query (ViewType) (queryString , Nothing)

However, it will not be compiled and I am not defining the error "type 'view-type."

I have tried to make an example of a specific class, then going through that type. I have many codes in the catalyst. Create instance I tried to use the MakeGenericType I tried to explicitly put the results in the list of "view-type":

  Slow view type = GetType (list ()). MakeGenericType (GetType (vw_EmployeeProductDetails)) List = Activator.CreateInstance (ViewType) List = conn.Query (queryString, Nothing)  

None of the above (as well as more dead ends) work Have done The code above gives me a square (a common object that can not be easily shown in the grid, even if it has the right properties, without throwing it back into any dataset / dataset).

I am studying more about whether I can get the compiler to recognize query , but I still can not understand How can all this be put together or if that approach will work (like all my viewcases will inherit from the general category?).

This code will not be compiled for the same reason:

  Slow view type = GetType (list  

when list2 < / Code> ), View-Type is not defined. How can I completely define it, if it is possible, or if I want to scrap the whole viewpoint, I have lost it.

Can someone provide insight on whether this is possible? If so, how can I apply it? If not, is there a suitable option in this situation?

Your generic query function should accept the usual type parameter: Public function MyQueryFunction (TK) (query) String in the form of strings) as the list of (t) return conn.Query (TK) (queryString, nothing) end function

and you call it this way Are:

  as the slow myresults list (of vw_EmployeeProductDetails) = MyQueryFunction (of vw_EmployeeProductDetails) (queryString)  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -