When I inherit from a class and serialize the new class I get all all properties. How can I prevent that? I have no control over the class that I inherit from. So I can\'t add
This was the solution I came up with.
public void WriteXml(XmlWriter writer)
{
foreach (PropertyInfo propertyInfo in this.GetType().GetProperties())
{
string name = propertyInfo.Name;
if (propertyInfo.DeclaringType != typeof(A))
{
object obj = propertyInfo.GetValue(this, null);
if (obj != null)
{
writer.WriteStartElement(name);
string value = obj.ToString();
writer.WriteValue(value);
writer.WriteEndElement();
}
}
}
}