Serialization fails (Resolved)
Hey, I've just run into a weird problem.
This class serializes fine:
Code:
[Serializable]
public struct KarmaRule
{
public string Rule;
public double Value;
};
Now, "Rule" is a Regular Expression. I figured the Regex class probably isn't serializable, but I gave it a try anyway:
Code:
[Serializable]
public struct KarmaRule
{
public Regex Rule;
public double Value;
};
No dice. It fails. So I thought, here's an easy work around:
Code:
[Serializable]
public struct KarmaRule
{
public string Rule;
public double Value;
// after the struct is deserialized,
// set xRule = new Regex(Rule, RegexOptions.Compiled)
[NonSerialized]
public Regex xRule;
};
But it doesn't work! It says "There was an error reflecting type KarmaRule." What gives? It's not supposed to serialize something marked NonSerialized, and it works fine without the Regular Expression as part of the struct.
Edit: I'm using an Xml Serializer. I was looking for the [XmlIgnore] Attribute. Stupid me.