I have the following partial
class created by running xsd /c
against an XML schema file:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="example.com")]
public partial class FRUITQueryType {
private string fruitTypeField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string FruitType {
get {
return this.fruitTypeField;
}
set {
this.fruitTypeField = value;
}
}
}
Although the type is string
, I know there are only three possible values for that field, say Banana
, Orange
, and Blueberry
.
In another part of the program, I check the content of that field:
// assume fruit is an instance of FRUITQueryType
if (fruit.FruitType == "Banana")
{
// do something
}
However, since there are only a few possible values for the field, this approach does not feel neat. I think it would be better if I could check the value of the field somewhat along these lines:
if (fruit.FruitType == FRUITQueryType.FruitType.Banana) // or something similar
Is there any point in achieving this?
If so, what's the best way to do it? By creating a class/struct with three static members containing Banana
, Orange
and Blueberry
?