开发者

.NET XML Serialization, possibly to use a different method name than PropertySpecified for ignoring properties?

开发者 https://www.devze.com 2023-01-03 00:30 出处:网络
I have a bunch of classes that I intend to serialize in order to transport over a webservice call. These classes a开发者_如何学Clready have properties that return whether a given \"real\" property ha

I have a bunch of classes that I intend to serialize in order to transport over a webservice call.

These classes a开发者_如何学Clready have properties that return whether a given "real" property has a value or not, that is ingrained in a lot of code of our product.

Is it possible, for instance through attributes, for me to specify that each "real" property should be included if a specified other property returns true, but not one that is called RealPropertyNameSpecified?

ie. for instance if I have this class:

[XmlType("test")]
public class TestClass
{
    [XmlIgnore]
    public bool NameHasGotAValue { get; set; }

    [XmlElement("name")]
    public string Name { get; set; }
}

Is it possible for me to use the NameHasGotAValue as the "*Specified" method for the Name property, or is my only option to either rename NameHasGotAValue, add a NameSpecified method, or implement IXmlSerializable?


HI,

For my knowledge, in order to satisfy you requisites, the implementation of the interface iXMLSerializable is the best solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消