Hi,
I have an object that I'd like to serialize and distribute between processes as efficiently as possible. The object itself has a reference to another object like so:
public class Foo
{
// Unique Identifier:
public int Id;
public Bar Bar;
}
public class Bar
{
// Unique Identifier:
public int Id;
}
The thing is that I only want to serialize Foo and run it over the wire. I'd rather not include Bar in what I send over the wire because it is known on the other side and sending it would waste my "bandwidth".
What I thought of doing is this:
At Serialization time, I'd serialize the reference to Bar (Foo.Bar) as an int containing: Bar.Id (which is a unique identifier for Bar instances)
Only Foo will be sent across the wire (containting the int instead of the Bar property).
At deserialization time I'd get the int, fetch the correct Bar from a repository and put it into the Foo.Bar property.
Is this a valid approach to the task of limiting the object graph being serialized? Is there a better way of doing this?