开发者

Easiest way to assign text content element to XmlNode[] 'Any' property from bound class?

Given this:

class foo 
{
    public XmlNode[] Any { get;set;}
}

What's the easiest way to do this:

foo f = new foo();
f.Any  = "some text content";

The above sample is an simplification, the actual class is a bound class generated by XSD.exe with an xs:an开发者_开发百科y element.


This is one approach:

foo f = new foo();
f.Any  = new XmlNode[] 
            { 
                new XmlDocument().CreateTextNode("some text content")
            };

This seems to be the simplest method I can find.


Any is an array of XmlNode so clearly you cannot assign a string to it.

you could assign a new array and then you can put XmlNode instances inside by index.

if I had to do something similar I would have a collection instead of an array and I would initialize the collection in the Foo's constructor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜