If I have a class which has a property that I wish to be serializable

public string Name
        {
            get { return name; }
            set { name = value; }           // How can this be private and be used for XML serialization?
        }

How can I prevent other classes from using the setter and only allow the built in System.Xml.Serialization serializer to use it?

public string Name {
    get { return name; }
    private set { name = value; }
}

And last I checked, serialization doesn't use set/get, it uses reflection. You'd also mark the variable name as the data member, not the property.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.