Example #1
0
        public static string Serialize <T>(T contents) where T : class
        {
            var buffer = new StringBuilder();

            using var writer = new StringWriter(buffer);

            DataSetSerialization.CreateSerializer().Serialize(writer, contents, typeof(T));

            return(buffer.ToString());
        }
        protected override JsonContract CreateContract(Type objectType)
        {
            var contract = base.CreateContract(objectType);

            // the omnisharp library specifies the NumberEnumConverter on some of the enum types
            // which supercedes our serialization settings
            if (objectType.IsEnum && !(contract.Converter is StringEnumConverter))
            {
                // force our converter on enum types
                contract.Converter = DataSetSerialization.CreateEnumConverter();
            }

            return(contract);
        }
Example #3
0
 public static T?Deserialize <T>(string contents) where T : class
 {
     using var reader = new JsonTextReader(new StringReader(contents));
     return(DataSetSerialization.CreateSerializer().Deserialize <T>(reader));
 }