public void GivenSubClassesValues_WhenDeserialize_ShouldPass()
        {
            var keyValues = new Dictionary <string, string>
            {
                ["IntValue"]            = "52",
                ["StrValue"]            = "string3",
                ["ClassType"]           = "Second",
                ["SubClass1:ClassName"] = "ClassName1",
                ["SubClass1:SubValue"]  = "10",
                ["SubClass2:ClassName"] = "ClassName2",
                ["SubClass2:SubValue"]  = "100",
            };

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddInMemoryCollection(keyValues)
                                           .Build();

            Main subject = new Main();

            configuration.Bind(subject);

            subject.IntValue.Should().Be(keyValues[nameof(subject.IntValue)].ConvertToType <int>());
            subject.StrValue.Should().Be(keyValues[nameof(subject.StrValue)].ConvertToType <string>());
            subject.ClassType.Should().Be(keyValues[nameof(subject.ClassType)].ConvertToType <ClassType>());

            subject.SubClass1.Should().NotBeNull();
            subject.SubClass1 !.ClassName.Should().Be(keyValues["SubClass1:ClassName"].ConvertToType <string>());
            subject.SubClass1 !.SubValue.Should().Be(keyValues["SubClass1:SubValue"].ConvertToType <int>());

            subject.SubClass2.Should().NotBeNull();
            subject.SubClass2 !.ClassName.Should().Be(keyValues["SubClass2:ClassName"].ConvertToType <string>());
            subject.SubClass2 !.SubValue.Should().Be(keyValues["SubClass2:SubValue"].ConvertToType <int>());
        }
 public ValuesImpl(string stringValue, int intValue, DateTime dateTimeValue, long?nullableValue,
                   decimal?nullableDecimalValue)
 {
     StringValue          = stringValue;
     IntValue             = intValue;
     DateTimeValue        = dateTimeValue;
     NullableValue        = nullableValue;
     NullableDecimalValue = nullableDecimalValue;
     Names     = new[] { "A", "B", "C" };
     SubValues = new SubValue[] { new SubValueImpl("A") };
     Strings   = new Dictionary <string, string>
     {
         { "A", "Aye" },
         { "B", "Bee" }
     };
     StringSubValues = new Dictionary <string, SubValue>
     {
         { "A", new SubValueImpl("Eh") },
         { "B", new SubValueImpl("Be") }
     };
 }
        private static DataTable CSV2Table(byte[] lstBytes)
        {
            string Separator = ",";

            DataTable dt = new DataTable();

            string strTable = System.Text.Encoding.UTF8.GetString(lstBytes);

            string[] lstRows = strTable.Split(new string[] { "\n" }, StringSplitOptions.None);
            //replaced Environment.NewLine with \n, because UNIX formatting does not have \r character
            if (lstRows.Length == 0)
            {
                return(dt);
            }

            foreach (string Header in lstRows[0].Split(new char[] { ',' }))
            {
                //lets remove white space chars from the column's name
                dt.Columns.Add(RemoveWhiteSpaces(Header));
            }

            for (int i = 1; (i < lstRows.Length - 1); i++)
            {
                ArrayList lstValues = new ArrayList();
                string    Value     = lstRows[i];

                bool          WithinQuotes = false;
                int           k            = 0;
                StringBuilder SubValue     = new StringBuilder();
                while (k < Value.Length)
                {
                    if (Value[k].ToString() == Separator)
                    {
                        //check is it new column
                        if (!WithinQuotes)
                        {
                            //yes, its new column
                            lstValues.Add(SubValue.ToString());
                            SubValue = new StringBuilder();
                            k++;
                            continue;
                        }
                    }

                    if (Value[k].ToString() == "\"")
                    {
                        //check is it begin/end of new string column or just quote char
                        if (k < Value.Length - 1)
                        {
                            if ((Value[k + 1].ToString() == "\""))
                            {
                                //this is quote char, replace it with single quote and move cursor next to it
                                SubValue.Append(Value[k]);
                                k++;
                            }
                            else
                            {
                                //this is begin/end of new string column - skip quote char and reverse WithinQuotes flag
                                WithinQuotes = !WithinQuotes;
                            }
                        }
                    }
                    else
                    {
                        SubValue.Append(Value[k]);
                    }

                    k++;
                }

                if (SubValue.ToString() != "")
                {
                    lstValues.Add(SubValue.ToString());
                }

                //add new row to DataTable
                DataRow dr = dt.NewRow();
                for (k = 0; k < dt.Columns.Count; k++)
                {
                    try
                    {
                        dr[k] = lstValues[k];
                    }
                    catch (Exception Exc)
                    {
                        Exceptions.LogException(Exc);
                    }
                }
                dt.Rows.Add(dr);
            }

            return(dt);
        }