sql
html
php
iphone
c
python
database
android
ruby-on-rails
objective-c
visual-studio
eclipse
html5
facebook
oracle
cocoa
apache
mvc
asp
dom
The XMLIgnoreAttribute can be applied to fields that you don's want serialized. For example,
public class Child { [XmlIgnore] public Parent MyParent; public Child(Parent parent) { MyParent = parent; } }
But as far as serializing a reference to the field, you'd have to provide more info on how you plan to persist the object that the reference points to. What is your reason to not just serialize the Parent member (in your case)? It's common to serialize all the public members that are needed.
Parent
If you just want to use serialization to clone, something like this should work:
private static Parent Clone(Parent parent) { Parent parentClone = null; lock (m_lock) // serialize cloning. { IFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); using (stream) { formatter.Serialize(stream, parent); stream.Seek(0, SeekOrigin.Begin); parentClone = (Parent)formatter.Deserialize(stream); } } return parentClone; }
Sounds like you might need to implement your own serialization and deserialization functionality.
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.getobjectdata.aspx
Here's an extract from MSDN
[Serializable] public class Person : ISerializable { private string name_value; private int ID_value; public Person() { } protected Person(SerializationInfo info, StreamingContext context) { if (info == null) throw new System.ArgumentNullException("info"); name_value = (string)info.GetValue("AltName", typeof(string)); ID_value = (int)info.GetValue("AltID", typeof(int)); } [SecurityPermission(SecurityAction.LinkDemand,Flags = SecurityPermissionFlag.SerializationFormatter)] public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) throw new System.ArgumentNullException("info"); info.AddValue("AltName", "XXX"); info.AddValue("AltID", 9999); } public string Name { get { return name_value; } set { name_value = value; } } public int IdNumber { get { return ID_value; } set { ID_value = value; } } }