Aurrin
April 17th, 2009, 02:15 AM
Okay, I'm writing an IRC bot with plugins, that responds to various commands like "!roll d20" and such. In order to keep these as flexible as possible, I'm designing it to use regular expressions for triggers for the various plugins. (i.e. "!roll (?<Argument>.*)" for one plugin, "!trope (?<Argument>)" for another, etc.) And in order to persist the settings, I'm storing them in an XML file, and using serialization to do the heavy lifting. It works beautifully...
...except for the regexes. Ideally, they should look something like this:
public class PluginSettings
{
...
[XmlArray]
[XmlArrayItem(ElementName="Trigger")]
public List<Regex> Triggers;
...
}
and produce
...
<Triggers>
<Trigger>!roll (?<Argument$gt;.*)</Trigger>
<Trigger>!trope (?<Argument$gt;.*)</Trigger>
</Triggers>
...
But instead, it produces:
...
<Triggers>
<Trigger />
<Trigger />
</Triggers>
...
I've tried adding the DataType parameter to the XmlArrayItem attribute, and it complains that that isn't supported for non-primitive types. The Type parameter as "string" throws an error and as "Regex" does nothing. System.Text.RegularExpressions.Regex is marked with the Serializable attribute, so why does it produce nothing? Does anyone know a way to make it serialize to XML as string elements?
...except for the regexes. Ideally, they should look something like this:
public class PluginSettings
{
...
[XmlArray]
[XmlArrayItem(ElementName="Trigger")]
public List<Regex> Triggers;
...
}
and produce
...
<Triggers>
<Trigger>!roll (?<Argument$gt;.*)</Trigger>
<Trigger>!trope (?<Argument$gt;.*)</Trigger>
</Triggers>
...
But instead, it produces:
...
<Triggers>
<Trigger />
<Trigger />
</Triggers>
...
I've tried adding the DataType parameter to the XmlArrayItem attribute, and it complains that that isn't supported for non-primitive types. The Type parameter as "string" throws an error and as "Regex" does nothing. System.Text.RegularExpressions.Regex is marked with the Serializable attribute, so why does it produce nothing? Does anyone know a way to make it serialize to XML as string elements?