Passing CSLA BO Object by ref as object

Passing CSLA BO Object by ref as object

Old forum URL: forums.lhotka.net/forums/t/4554.aspx


Vinodonly posted on Tuesday, March 25, 2008

In one of my methods I need to pass CSLA Bo as object type and as ref as that method needs to change the BO. But I'm getting complie time error.

If I define the method as generic type and pass in the type of BO and the object then it is working fine.

Can anybody guide me on how to solve this issue.

RobKraft replied on Monday, March 31, 2008

What error do you receive?

If you are casting the class to an object; then you can only call the methods that are available to any "object", unless you in turn cast the object to something else.

If you are casting the object to an interface, you can call any methods defined for that interface.

Vinodonly replied on Tuesday, April 01, 2008

I'm getting a compile time error that cannot convert from my BO to ref object.

This is actually a generic Save Handler. My existing method signature defines it in this way :-

SaveRecord<T>(ref T Bo) : where T : Csla.Core.ISavable, System.ICloneable

The problem in this case is that I have to pass in the Bo type also. I have a base class where I want to accept all Business Objects as type of Object and which will perform this save operation automatically.

If passing as object type is sucessfull then I can simply cast to Csla.Core.ISavable, System.ICloneable and perform Clone and Save Operations.

Kindly advise your comments.

Copyright (c) Marimer LLC