在喝着早晨的咖啡时,我偶然发现了一个我不太清楚的错误。 我试图通过它的EnumMember值来序列化Enum
如图所示
public enum LocationStatus
{
[EnumMember(Value = "Open")]
Open = 0,
[EnumMember(Value = "Closed")]
Closed = 1,
[EnumMember(Value = "On Hold")]
OnHold = 2,
[EnumMember(Value = "Closed Test")]
ClosedTest = 3,
[EnumMember(Value = "Open Test")]
OpenTest = 4,
[EnumMember(Value = "Under Construction")]
UnderConstruction = 5
}
在这里
public class Location
{
public int LocationId { get; set; }
public string LocationName { get; set; }
public string LocationAddress { get; set; }
public double Longitude { get; set; }
public double Latitude { get; set; }
[JsonProperty("Status")]
[JsonConverter(typeof(StringEnumConverter))]
public LocationStatus Status { get; set; }
public DateTime Created { get; set; }
public Organization Organization { get; set; }
public ICollection<ConnectionPoint> ConnectionPoints { get; set; }
}
但问题是它只给出了第一个值,我得到了0,1和2的数据库条目,但我得到了所有这些的Open。
{
$id: "5",
LocationId: 3,
LocationName: "Legoland",
LocationAddress: "Nordmarksvej 9, 7190, Billund",
Longitude: 8.883983,
Latitude: 55.94971,
Status: "Open",
Created: "0001-01-01T00:00:00.0000000",
Organization: {
$id: "6",
OrganizationId: 3,
OrganizationName: "Lego.inc",
Locations: null,
Users: null
},
ConnectionPoints: null
},
{
$id: "7",
LocationId: 4,
LocationName: "BLiS Reijerwaard",
LocationAddress: "Pesetastraat 40, 2991 XT, Barendrecht",
Longitude: 4.547588,
Latitude: 51.872464,
Status: "Open",
Created: "0001-01-01T00:00:00.0000000",
Organization: {
$id: "8",
OrganizationId: 4,
OrganizationName: "BLiS",
Locations: null,
Users: null
},
ConnectionPoints: null
},
有人知道为什么会这样吗?任何帮助表示赞赏!