示例#1
0
        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()));
        }
示例#2
0
        /// <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()));
        }
示例#3
0
        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()));
        }
示例#4
0
        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);
        }
示例#5
0
 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;
         }
     }
 }
示例#6
0
 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;
         }
     }
 }
示例#7
0
 public static string Serialize(object value)
 {
     return(JsonConvert.SerializeObject(value, BridgeSerializerSettings.GetSerializerSettings()));
 }
示例#8
0
 public static T Deserialize <T>(TypeProxy data)
 {
     return(JsonConvert.DeserializeObject <T>(data.SerializedData, BridgeSerializerSettings.GetSerializerSettings()));
 }
示例#9
0
 public static T Deserialize <T>(ref string data)
 {
     return(JsonConvert.DeserializeObject <T>(data, BridgeSerializerSettings.GetSerializerSettings()));
 }