[Serializable]
public class ProfilesCollection : ObservableCollection<Profile>
{
public ProfilesCollection()
{
}
}
[Serializable]
public class Profile : ObservableCollection<SomeData>
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
OnPropertyChanged(new PropertyChangedEventArgs("Name"));
}
}
public Profile()
{
}
}
[Serializable]
public class SomeData : INotifyPropertyChanged
{
// some properties
public SomeData()
{ ... }
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
I am trying to serialize ProfilesCollection (or Profile) object using XmlSerializer:
using (var writer = new StreamWriter("1.xml"))
{
var xs = new XmlSerializer(typeof(ProfilesCollection));
xs.Serialize(writer, _profiles);
}
but .xml doesn't contain Name property which is in Profile class. Everything except that is ok. What should I do to fix that?