Example #1
0
        public static string ToJson <T>(T target, bool readable = false)
        {
            ISerializeUtf8JsonModule module     = SerializeUtf8JsonModule;
            ISerializer <string>     serializer = GetSerializer(module, readable);

            return(serializer.Serialize(target));
        }
Example #2
0
        private static ISerializer <string> GetSerializer(ISerializeUtf8JsonModule module, bool readable)
        {
            string name = readable
                ? module.SerializeModule.Description.DefaultTextReadableSerializerName
                : module.SerializeModule.Description.DefaultTextCompactSerializerName;

            return(module.SerializeModule.Provider.Get <string>(name));
        }
Example #3
0
        public static T FromJson <T>(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(text));
            }

            ISerializeUtf8JsonModule module     = SerializeUtf8JsonModule;
            ISerializer <string>     serializer = GetSerializer(module, false);

            return(serializer.Deserialize <T>(text));
        }
Example #4
0
        public static string ToJson(object target, bool readable = false)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            ISerializeUtf8JsonModule module     = SerializeUtf8JsonModule;
            ISerializer <string>     serializer = GetSerializer(module, readable);

            return(serializer.Serialize(target));
        }
Example #5
0
        public static object FromJson(string text, Type targetType)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(text));
            }
            if (targetType == null)
            {
                throw new ArgumentNullException(nameof(targetType));
            }

            ISerializeUtf8JsonModule module     = SerializeUtf8JsonModule;
            ISerializer <string>     serializer = GetSerializer(module, false);

            return(serializer.Deserialize(targetType, text));
        }