Hey everybody, I've got a couple of tables during my database plus they all have a different inherited kind of a DataRow.

Additionally I've got a class that's designed to handle several things during my DataGrid (My database Tables are attached to DataGrids).

To be able to do this, among the techniques within this DataGrid handler needs to cast the rows towards the exact inherited kind of a DataRow.

something similar to this: (TempDataRow as DataRowTypeThatInheritsFromRegularDataRow).SpecialParameter = something

To be able to do this, I must pass the technique the inherited DataRow type, therefore it will understand how to perform the casting.

The technique will normally seem like this:

public void DoSomthing(DataRowType Type)

the truth is I'm not sure how you can pass the kind. Regular 'Type' type doesn't compile. and when I pass just 'DataRow' it will not understand how to perform the casting.

any suggestions? Thanks.

If you work with CFour., then have you thought about using the 'dynamic' type?

dynamic row = getDataRow();
doSomething( row );

public void doSomething( DataRowTypeThatInheritsFromRegularDataRow row )
    // <insert code here>

public void doSomething( SomeOtherDataRowType row )
    // <insert code here>

This situation should select at run-time which function to call, based on what getDataRow() really returns.

For more reading through of dynaminc see msdn

You will find various ways you could do this this.

First, you could discover a typical base class or interface that types share, after which have DoSomething() take that base class or interface, or if you wish to be totally dynamic, you could utilize reflection. It's difficult to inform you the way to get it done, since you haven't given any concrete example:

using System.Reflection;
public void DoSomething(object foo) {
    var dataType = foo.GetType();

    type.GetProperty("SomeDynamicName").SetValue(foo, someOtherValue);

(though should you be using CFour., as TK highlights, you can only use the dynamic type and that would be that!)

You could utilize:

TempDataRow as Type.GetType("DataRowTypeName")