我需要将以下类重写为 Json.Net JsonConverter 以使代码与 Xamarin mono for android 一起使用
private class ResourceConverter : JavaScriptConverter
{
public ResourceConverter() { }
public override IEnumerable<Type> SupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new Type[] { typeof(SystemCertificate) })); }
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
if (dictionary.ContainsKey("Certificate"))
{
SystemCertificate customerResource = new SystemCertificate();
customerResource.SystemID = dictionary["SystemID"].ToString();
string base64Text = dictionary["Certificate"].ToString();
customerResource.Certificate = Convert.FromBase64CharArray(base64Text.ToCharArray(), 0, base64Text.Length);
return customerResource;
}
return null;
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
if (obj is SystemCertificate)
{
SystemCertificate systemCertificate = obj as SystemCertificate;
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("SystemID", systemCertificate.SystemID);
return dic;
}
return null;
}
}
问题是JsonConverter的序列化基础方法(WriteJson)是一个void,我真的不知道该怎么办,请帮帮我。
private class ResourceConverterGen2 : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override bool CanConvert(Type objectType)
{
throw new NotImplementedException();
}
}