Question

I can find lots of examples where people pass single parameters in to CLR code like this:

public static void Example(SqlDateTime param1, SqlInt32 param2) {
}

I've also seen lots of code where people pass in parameters which are then used to select data from SQL within code (using an SQLCommand.) Isn't it possible to pass the equivalent to a DataTable object in to the CLR code and manipulate that?

Thanks,

Joe

Was it helpful?

Solution

You can always pass an equivalent Object in CLI depending on type (Managed/Native) of object.

public class NativeObject
{
private:
    int id;
    string msg;
    SomeClass obj;
    .......
public:
    string getMessage(){return msg;}
    int getID(){return id;}
    ...
}

It's Managed equivalent will be

public ref class ManagedObject
{
private:
    NativeObject* native;
public:
    ManagedObject(NativeObject* obj){
        native = obj;
    }
    String^ getMessage(){
        convertNativeToCLI(native->getMessage()); //you can use marshaling to implement convertNativeToCLI method. 
    }
    int getID(){
        return native->getID();
    }
    ...
}

and you will need a Binder or Interface class to convert one object from one form to another. Generally we use this approach when we have complex objects. If we have only few simple data object then this approach will unnecessary put extra overhead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top