Ejemplo n.º 1
0
        public static string ToJsonString(this object dataContract, IEnumerable <Type> types = null)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(dataContract.GetType(), types, int.MaxValue, false, null, true);
            string text = JsonExtension.ToJsonStringCore(serializer, dataContract);

            if (!string.IsNullOrEmpty(text) && JsonExtension.unsafeCharactersRegex.IsMatch(text))
            {
                text = JsonExtension.unsafeCharactersRegex.Replace(text, new MatchEvaluator(JsonExtension.ReplaceWithEscapedCode));
            }
            return(text);
        }
Ejemplo n.º 2
0
        public static object JsonDeserialize(this string text, Type targetType, IEnumerable <Type> types = null)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(targetType, types);

            return(JsonExtension.JsonDeserializeCore(text, serializer));
        }
Ejemplo n.º 3
0
        public static T JsonDeserialize <T>(this string text, IEnumerable <Type> types = null)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T), types);

            return((T)((object)JsonExtension.JsonDeserializeCore(text, serializer)));
        }