I understand that I must have public read and write properties on my class for MongoDB driver to serialize/deserialize my objects. however I want to know whether there is method/preferred method for hiding the write properties from the rest of my code?
eg.
class Product
{
private List<Release> releases;
public List<Release> Releases
{
get
{
return new List<Release>(releases); //I can protect 'releases' when reading by passing a copy of it
}
set
{
releases = value; //BUT how can I protect release when writing?
}
}
}
I want MongoDB to be able to serialize/deserialize my types but I don't want the rest of my code to be able to overwrite it's fields / properties that should otherwise have been private. Is there a pattern to handle this? I have thought about having a separate ProductDoc
class which is just used as a intermediary for getting Product objects into and out of MongoDB, but I'm not sure whether there is a better solution to this.