22 lines
519 B
C#
22 lines
519 B
C#
using System;
|
|
namespace ln.json.mapping
|
|
{
|
|
public class JSONEnumMapping : JSONMapping
|
|
{
|
|
public JSONEnumMapping(Type targetType)
|
|
:base(targetType)
|
|
{
|
|
}
|
|
|
|
public override JSONValue ToJson(JSONMapper mapper, object value)
|
|
{
|
|
return new JSONString(value.ToString());
|
|
}
|
|
public override object FromJson(JSONMapper mapper, JSONValue json)
|
|
{
|
|
return Enum.Parse(TargetType, json.ToNative().ToString());
|
|
}
|
|
|
|
}
|
|
}
|