开发者

XmlElementName - Change during runtime

开发者 https://www.devze.com 2023-01-15 06:50 出处:网络
I am implementing a class object that is serializable. something like this: StringWriter sw = new StringWriter();

I am implementing a class object that is serializable.

something like this:

  StringWriter sw = new StringWriter();
        XmlSerializerNamespaces ns = new XmlSerializerN开发者_运维百科amespaces();
        ns.Add("", "");

        System.Xml.Serialization.XmlSerializer x = 
              new System.Xml.Serialization.XmlSerializer(this.GetType());
        x.Serialize(sw, this,ns);

        return sw.ToString();

I want the child class/objects to have different names depending on a flag. is there a ways to change the ElementName of the class prop. during run time without write a custom WriteXml?


Yes, but you won't like it. IXmlSerializable

0

精彩评论

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