public static T Deserialize <T>(ref string data) { if (EnvironmentHelper.RunOnCLR()) { data = data.Replace("%CORE%", EnvironmentHelper.GetNetCoreVersion()); } else { data = data.Replace("%CORE%", "mscorlib"); } return(JsonConvert.DeserializeObject <T>(data, BridgeSerializerSettings.GetSerializerSettings())); }
/// <summary> /// This is a last chance of deserialization. /// In some scenario, it seem that Deserializer don't even call the CrossPlatformTypeBinder class /// and prevent some data to be deserialized. This helper is intended to force assembly rename before deserialization /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <returns></returns> private static T FallbackDeserialize <T>(string data) { if (CrossPlatformTypeBinder.isNetCore) { data = data?.Replace("mscorlib", "System.Private.CoreLib"); } else { data = data.Replace("System.Private.CoreLib", "mscorlib"); } return(JsonConvert.DeserializeObject <T>(data, BridgeSerializerSettings.GetSerializerSettings())); }
public static T Deserialize <T>(TypeProxy data) { string fixedJson; if (EnvironmentHelper.RunOnCLR()) { fixedJson = data.SerializedData.Replace("%CORE%", EnvironmentHelper.GetNetCoreVersion()); } else { fixedJson = data.SerializedData.Replace("%CORE%", "mscorlib"); } return(JsonConvert.DeserializeObject <T>(fixedJson, BridgeSerializerSettings.GetSerializerSettings())); }
public static string Serialize(object value) { string data = JsonConvert.SerializeObject(value, BridgeSerializerSettings.GetSerializerSettings()); if (EnvironmentHelper.RunOnCLR()) { data = data.Replace("System.Private.CoreLib", "%CORE%"); } else { data = data.Replace("mscorlib", "%CORE%"); } return(data); }
public static T Deserialize <T>(TypeProxy data) { try { return(JsonConvert.DeserializeObject <T>(data.SerializedData, BridgeSerializerSettings.GetSerializerSettings())); } catch (Exception) { try { return(FallbackDeserialize <T>(data.SerializedData)); } catch (Exception ex) { throw; } } }
public static T Deserialize <T>(ref string data) { try { return(JsonConvert.DeserializeObject <T>(data, BridgeSerializerSettings.GetSerializerSettings())); } catch (Exception) { try { return(FallbackDeserialize <T>(data)); } catch (Exception) { //Should bubble up throw; } } }
public static string Serialize(object value) { return(JsonConvert.SerializeObject(value, BridgeSerializerSettings.GetSerializerSettings())); }
public static T Deserialize <T>(TypeProxy data) { return(JsonConvert.DeserializeObject <T>(data.SerializedData, BridgeSerializerSettings.GetSerializerSettings())); }
public static T Deserialize <T>(ref string data) { return(JsonConvert.DeserializeObject <T>(data, BridgeSerializerSettings.GetSerializerSettings())); }