public RazorConfigurationSerializationTest()
        {
            var converters = new JsonConverterCollection();

            converters.Add(RazorExtensionJsonConverter.Instance);
            converters.Add(RazorConfigurationJsonConverter.Instance);
            Converters = converters.ToArray();
        }
示例#2
0
        public static JsonConverterCollection DefaultConveter()
        {
            JsonConverterCollection converters = new JsonConverterCollection();
            IsoDateTimeConverter    item       = new IsoDateTimeConverter {
                DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
            };
            EntityConverter converter2 = new EntityConverter();

            converters.Add(item);
            converters.Add(converter2);
            return(converters);
        }
        public static JsonConverterCollection RegisterRazorConverters(this JsonConverterCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            collection.Add(TagHelperDescriptorJsonConverter.Instance);
            collection.Add(RazorDiagnosticJsonConverter.Instance);
            collection.Add(RazorExtensionJsonConverter.Instance);
            collection.Add(RazorConfigurationJsonConverter.Instance);
            collection.Add(ProjectSnapshotHandleJsonConverter.Instance);

            return(collection);
        }
示例#4
0
        public void OneTimeSetup()
        {
            var contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new CamelCaseNamingStrategy
                {
                    OverrideSpecifiedNames = false,
                    ProcessDictionaryKeys  = true,
                }
            };

            DefaultSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.None,
                ContractResolver = contractResolver,
                Converters       = new JsonConverterCollection(),
            };

            var optimizedConverters = new JsonConverterCollection();

            optimizedConverters.Add(DoubleArrayConverter.Create(6));
            OptimizedSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.None,
                ContractResolver = contractResolver,
                Converters       = optimizedConverters,
            };
        }
示例#5
0
        public static void RegisterRazorConverters(this JsonConverterCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            for (var i = 0; i < RazorConverters.Count; i++)
            {
                collection.Add(RazorConverters[i]);
            }
        }
示例#6
0
        public static void RegisterRazorLiveShareConverters(this JsonConverterCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (collection.Contains(ProjectSnapshotHandleProxyJsonConverter.Instance))
            {
                // Already registered.
                return;
            }

            collection.Add(ProjectSnapshotHandleProxyJsonConverter.Instance);
            collection.RegisterRazorConverters();
        }
示例#7
0
        public static JsonSerializerSettings GetDefaultSerializerSettings()
        {
            JsonSerializerSettings serializerSettings1 = new JsonSerializerSettings();

            serializerSettings1.Formatting = (Formatting)1;
            JsonSerializerSettings  serializerSettings2  = serializerSettings1;
            JsonConverterCollection converterCollection1 = new JsonConverterCollection();

            converterCollection1.Add(new StringEnumConverter());
            JsonConverterCollection converterCollection2 = converterCollection1;
            IsoDateTimeConverter    dateTimeConverter1   = new IsoDateTimeConverter();

            dateTimeConverter1.DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffK";
            IsoDateTimeConverter dateTimeConverter2 = dateTimeConverter1;

            converterCollection2.Add(dateTimeConverter2);
            JsonConverterCollection converterCollection3 = converterCollection1;

            serializerSettings2.Converters = converterCollection3;
            return(serializerSettings1);
        }
示例#8
0
 public static void RegisterOmniSharpRazorConverters(this JsonConverterCollection collection)
 {
     collection.RegisterRazorConverters();
     collection.Add(OmniSharpProjectSnapshotHandleJsonConverter.Instance);
 }
示例#9
0
        public void Setup()
        {
            List <IEnumerable <long> > list = new List <IEnumerable <long> >();

            for (int i = 0; i < ArraysCount; i++)
            {
                var item = TheLongs.Concat(Enumerable.Range(0, 61).Select(x => 42L));
                if (Kind == CollectionFlavour.List)
                {
                    list.Add(item.ToList());
                }
                else if (Kind == CollectionFlavour.Array)
                {
                    list.Add(item.ToArray());
                }
                else if (Kind == CollectionFlavour.ROList)
                {
                    list.Add(item.ToList().ToImmutableList());
                }
                else if (Kind == CollectionFlavour.ROArray)
                {
                    list.Add(item.ToList().ToImmutableArray());
                }
                else if (Kind == CollectionFlavour.Enumerable)
                {
                    list.Add(AsEnumerable(item.ToArray()));
                }
                else
                {
                    throw new InvalidOperationException($"Unknown flavour: {Kind}");
                }
            }

            Data = list.ToArray();

            DefaultSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.None,
                ContractResolver = TheContractResolver,
                Converters       = new JsonConverterCollection(),
            };

            var optimizedConverters = new JsonConverterCollection();

            optimizedConverters.Add(LongArrayConverter.Instance);
            OptimizedSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.None,
                ContractResolver = TheContractResolver,
                Converters       = optimizedConverters,
            };

            {
                var json = JsonConvert.SerializeObject(Data, DefaultSettings);
                Console.WriteLine($"// LONGS-DATA-LENGTH[json.net]: {json.Length} chars");
            }
            {
                var json = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(Data, SystemSettings);
                Console.WriteLine($"// LONGS-DATA-LENGTH[system]: {json.Length} bytes");
            }
            {
                var json = JsonConvert.SerializeObject(Data, OptimizedSettings);
                Console.WriteLine($"// LONGS-DATA-LENGTH[optimized]: {json.Length} chars");
            }
        }