<commit_before>﻿namespace Serialization.Dcs
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.Serialization;
    using System.Xml;

    class Program
    {
        static void Main(string[] args)
        {
            bool serializeInput, configSettings;
            Console.WriteLine("DCS Configuration");

            Console.WriteLine("\nNo settings:");
            NoSettings();

            Console.WriteLine("\nUse Root Name and Namespace:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseRootNameAndNamespace(serializeInput, configSettings);

            Console.WriteLine("\nUse Known Types:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseKnownTypes(serializeInput, configSettings);

            Console.WriteLine("\nUse Contract Resolver:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseDataContractResolver(serializeInput, configSettings);

            Console.WriteLine("\nUse Preserve References:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UsePreserveReferences(serializeInput, configSettings);
        }

        private static void NoSettings()
        {
            var settings = new DataContractSerializerSettings();

            //var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            //    "<DummyClass><SampleInt>1</SampleInt></DummyClass>";

            var data = new DummyClass { SampleInt = 1 };
            var input = Utilities.Serialize(data, settings);

            var output = Utilities.Deserialize<DummyClass>(input, settings);
            Console.WriteLine("DummyClass.SampleInt: {0}", output.SampleInt);
        }

        private static void UseRootNameAndNamespace(bool serializeInput, bool configSettings)
        {
            const string SubstituteRootName = "SomeOtherClass";
            const string SubstituteRootNamespace = "http://tempuri.org";

            var settings = new DataContractSerializerSettings();
            if (configSettings)
            {<commit_msg>Added DCS tests for preserve references.<commit_after>﻿namespace Serialization.Dcs
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.Serialization;
    using System.Xml;

    class Program
    {
        static void Main(string[] args)
        {
            bool serializeInput, configSettings;
            Console.WriteLine("DCS Configuration");

            Console.WriteLine("\nNo settings:");
            NoSettings();

            Console.WriteLine("\nUse Root Name and Namespace:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseRootNameAndNamespace(serializeInput, configSettings);

            Console.WriteLine("\nUse Known Types:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseKnownTypes(serializeInput, configSettings);

            Console.WriteLine("\nUse Contract Resolver:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UseDataContractResolver(serializeInput, configSettings);

            Console.WriteLine("\nUse Preserve References:");
            Console.WriteLine("Serialize input? {Y/N}");
            serializeInput = Console.ReadLine().ToUpper() == "Y";
            Console.WriteLine("Configure DCS settings? {Y/N}");
            configSettings = Console.ReadLine().ToUpper() == "Y";
            UsePreserveReferences(serializeInput, configSettings);
        }

        private static void NoSettings()
        {
            var settings = new DataContractSerializerSettings();
            var dictionary = new XmlDictionary();
            settings.RootName = dictionary.Add(string.Empty);
            settings.RootNamespace = dictionary.Add(string.Empty);

            //var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            //    "<DummyClass><SampleInt>1</SampleInt></DummyClass>";

            var data = new DummyClass { SampleInt = 1 };
            var input = Utilities.Serialize(data, settings);

            var output = Utilities.Deserialize<DummyClass>(input, settings);
            Console.WriteLine("DummyClass.SampleInt: {0}", output.SampleInt);
        }

        private static void UseRootNameAndNamespace(bool serializeInput, bool configSettings)
        {
            const string SubstituteRootName = "SomeOtherClass";
            const string SubstituteRootNamespace = "http://tempuri.org";

            var settings = new DataContractSerializerSettings();
            if (configSettings)
            {
{'fraction_non_alphanumeric': 0.12592219986586184, 'fraction_numerical': 0.002012072434607646, 'mean_word_length': 2.4085714285714284, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 2, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2885893', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1459, 'n_words': 317}