Is it posible to dump/save an in memory object so that the dump contains both the state and methods and then transfer it across the wire. I'm primarily using C# but if this can be done in some other technology, that should be good .
By "the dump contains the methods", that would depend on the language and runtime a lot.
In typical statically typed OO languages, the methods of an object are determined by its type, so you only need to send an identifier for the type, assuming the recipient has the same code installed. The recipient just instantiates a blank object of that type and populates it with the received data.
"Sending the methods" could mean all kinds of things: negotiating with the recipient to see if they have certain assemblies (compiled code), if not then sending them (or telling it to download them from somewhere) then sending the data to instantiate the object with. Doing this automatically would typically be a massive security risk! Hence it rarely happens automatically.
This is essentially how a web server sends you a video. If you don't have the required plug-in, it gets you to download it, and then sends you the data to instantiate an instance of the plug-in.
With a very dynamic language like JavaScript, the division between code and data is more seamless. The following declaration is roughly equivalent to an object with a method:
{
counter: 5,
increment: function() { this.counter++; }
}
This snippet of text could be sent over the network, and then the recipient could use eval
to turn it into an actual object:
c.increment();
c.increment();
alert(c.counter); // displays 7
Again, this is essentially what modern web pages are: a combination of declared structure (in HTML) and small pieces of executable script, which are sent over the internet.