我正在尋找通過一個Web服務,其中包括一個枚舉類型作爲其成員之一返回以下類。Serialize枚舉爲int
[Serializable, XmlRoot("GeoCoordinate")]
public class GeoCoordinate
{
public enum AccuracyLevel
{
Unknown = 0,
Country = 1,
Region = 2,
SubRegion = 3,
Town = 4,
PostalCode = 5,
Street = 6,
Intersection = 7,
Address = 8,
Premise = 9
}
private AccuracyLevel _accuracy;
// ... more members
public AccuracyLevel Accuracy
{
get { return _accuracy; }
set { _accuracy = value;}
}
}
這工作正常,但將在形式返回結果:
<!-- ... -->
<Accuracy>Unknown or Country or Region or SubRegion or Town or
PostalCode or Street or Intersection or Address or Premise</Accuracy>
<!-- ... -->
而是表示枚舉一個字符串,我想它只會返回一個整數。這可以在不改變GeoCoordinate.Accuracy
的類型的情況下完成嗎?
重複:http://stackoverflow.com/questions/506368/how-do-i-serialize-an-enum-value-as-an-int – 2010-01-13 14:24:12