1

This will work

public class PleaseIgnoreMe
{
    [XmlIgnore]
    public string A { get; set; }
    [XmlIgnore]
    public string B { get; set; }
}

However, when I apply this

using System.Xml.Serialization;

[XmlIgnore]
public class PleaseIgnoreMe
{
    public string A { get; set; }
    public string B { get; set; }
}

the following error shows up.

Error 265 Attribute 'XmlIgnore' is not valid on this declaration type. It is only valid on 'property, indexer, field, param, return' declarations.

What is the equivalent [XmlIgnore] for a class ? I need all of its properties to be ignored without specifying it one by one.

Jeson Martajaya
  • 6,996
  • 7
  • 54
  • 56
  • 2
    By default, classes and their members are non-serializable – Mitch Wheat May 27 '15 at 23:55
  • I am looking for a way to enforce this default. – Jeson Martajaya May 27 '15 at 23:58
  • That's not what the question title states...also, "I want to declare the entire class as not serializable" – Mitch Wheat May 27 '15 at 23:59
  • What would be the point of serialising a class where all properties are ignored? – Guffa May 28 '15 at 00:11
  • 2
    The actual case is complicated, but in short, I have classes who use custom serializer. They normally do not get serialized by the standard XmlSerializer. However, when I enable project-wide inside the csproj, these classes get picked up. It causes build error because some of their property names conflict with each other. I can apply [XmlIgnore] to those properties, but they are just too many. – Jeson Martajaya May 28 '15 at 16:21

0 Answers0