Remote object equality

L

Looch

All,

Given the two classes below:

namspace Namespace1

public class MyClass
{
public string test1;
public string test2;
}

..........

namespace Namespace2

public class MyClass
{
public string test1;
public string test2;
}

.........................

static void Main (string[], args)
{
myClass1 = new Namespace1.MyClass();
myClass2 = new Namespace2.MyClass();

myClass1.test1 = "Test1";
myClass1.test2 = "Test2";

myClass1 = mcClass2; //Problem because of the diffrent namespaces.

}

How can I set the two equal without iterating through each of the
variables setting each equal?

A little background, the Namespace2.MyClass object is a remotable
object with about one hundred class variables and setting each one,
one at a time is making for a somewhat chatty interface. What can I do
to set the two objects equal without iterating through the whole
class?

Thanks for any suggestions.
 
F

Family Tree Mike

Can you make the class a part of a shared utility library between remote and
local so that the classes are really identical?
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

Well, the objects (unless you have a specific override to Equals which
allows it) will NEVER be equal, since they are different types.

If you are using one as a facade for the other remotable object, then do
as Family Tree Mike says, and use a shared assembly so you can use the same
object.

If you are not doing that, then you will have to override the Equals
method on one of the types to perform your comparison to see if they are
"equal". However, this might have an impact on what you are doing now
(depending on how the types are used otherwise) and you will also have to
override GetHashCode.

If you are simply looking to assign the values from one to another, then
have another object exposed through remoting (or a method on the original
remoted type) which will take the instance of your other object, and then
perform the copy in the server and return it back to you.
 
L

Looch

Thanks both for the replies.

I am trying to simply copy the values from one to the other, however I
found this on MSDN:

"Try to reduce the number of calls used to complete a logical unit of
work. The following code shows an example of calling a component, by
using a chatty interface. Notice how the inefficient (chatty)
interface design forces the caller to traverse the remoting boundary
three times to perform the single task of saving customer details.


MyComponent.Firstname = "bob";
MyComponent.LastName = "smith";
MyComponent.SaveCustomer();

The following code shows how the same functionality should be
implemented to reduce the operations and boundary crossings required
to complete the single logical operation.

MyComponent.SaveCustomer( "bob", "smith");"

The top example is exactly what I'm doing, about a hundred times
though and seems to be slowing down this application. I have used the
lower example but when the number of paramters grew to about 100, I
decided to use an object (Namespace1.MyClass) instead.

I could go back to passing parameters. Other than the admin headache,
is there any disadvantage to passing 100 parameters?

I appreciate the help, thanks again.
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

No, not really. It's assumed the parameters are going to be smaller
than what it would take to remote a full class instance over (since you are
breaking it down).

The important thing is to reduce the number of calls. Whether you send
a class, or 100 parameters, the remoting infrastructure is going to make one
call across the network (instead of making 100 calls for setting each
property).
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Looch said:
Thanks both for the replies.
The following code shows how the same functionality should be
implemented to reduce the operations and boundary crossings required
to complete the single logical operation.

MyComponent.SaveCustomer( "bob", "smith");"

It does make sense, you are minimizing the transfer.
The top example is exactly what I'm doing, about a hundred times
though and seems to be slowing down this application. I have used the
lower example but when the number of paramters grew to about 100, I
decided to use an object (Namespace1.MyClass) instead.

100 parameters??? You mean you have a class with 100 properties?
I honestly never seen such a class.

There might me a better solution tough. If both classes define the same
properties and you can use reflection to copied them in a loop. Much better
than pass 100 parameters !!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top