开发者

XML serialization in C#

I have a class that looks like the following:

class SomeClass
    {
        private int _property1;
        [XmlAttribute("Property1")]
        public int Property1
        {
            get { return _property1; }
            set { _property1 = value; }
        }
        private int _property2;
        [XmlAttribute("Property2")]
        public int Property2
        {
            get { return _property2; }
            set { _property2 = value; }
        }

        private string _property3;
        public string Property3
        {
            get { return _property3; }
            set { _prope开发者_如何转开发rty3 = value; }
        }

        public SomeClass()
        {
        }
    }

I need to serialize it using XmlSerializer in the following format:

<SomeClass Property1="NNNNN" Property2="NNNNN">
     Value_of_Property3
</SomeClass>

However, I can't figure how can I serialize the value of Property3 without adding a node for Property3. Is there a to serialize the string in Property3 without adding a node for it?


Add [XmlText()] attribute to Property3.


[XmlText]
public string Property3
{
    get { return _property3; }
    set { _property3 = value; }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜