Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Remote object equality

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Looch - 06 Feb 2008 16:48 GMT
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.
Family Tree Mike - 06 Feb 2008 16:57 GMT
Can you make the class a part of a shared utility library between remote and
local so that the classes are really identical?

> All,
>
[quoted text clipped - 42 lines]
>
> Thanks for any suggestions.
Nicholas Paldino [.NET/C# MVP] - 06 Feb 2008 17:14 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> All,
>
[quoted text clipped - 42 lines]
>
> Thanks for any suggestions.
Looch - 06 Feb 2008 17:25 GMT
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.
Nicholas Paldino [.NET/C# MVP] - 06 Feb 2008 17:38 GMT
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).

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Thanks both for the replies.
>
[quoted text clipped - 26 lines]
>
> I appreciate the help, thanks again.
Ignacio Machin ( .NET/ C# MVP ) - 06 Feb 2008 19:10 GMT
Hi,

> 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 !!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.