c# - Type-ing: how to pass the type? -


i have few tables in database , contain different inherited type of datarow.

in addition have class supposed handle things in datagrid (my database tables connected datagrids).

in order that, 1 of methods in datagrid handler has cast rows exact inherited type of datarow.

something this: (tempdatarow datarowtypethatinheritsfromregulardatarow).specialparameter = something;

in order that, have pass method inherited datarow type, know how casting.

the method this:

public void dosomething(datarowtype type) { (tempdatarow type).specialparameter = something; }

how pass type? regular 'type' type not compile. , if pass 'datarow' won't know how casting.

if using c# 4.0, have considered use of 'dynamic' type?

dynamic row = getdatarow(); dosomething( row );  public void dosomething( datarowtypethatinheritsfromregulardatarow row ) {     // <insert code here> }  public void dosomething( someotherdatarowtype row ) {     // <insert code here> } 

this example should choose @ run-time function call, based upon getdatarow() returns.

for further reading of dynaminc see msdn


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -