Exemple #1
0
            // Utility to convert Section into Object[]
            public static object[] ConvertProfileToObjectArray(PrivateProfile profile)
            {
                // Copy Section Names
                string[] section_names = new string[profile.Sections.Count];
                profile.Sections.Keys.CopyTo(section_names, 0);

                // Copy Entries
                string[][][] entries = new string[profile.Sections.Count][][];
                var          i       = 0;

                foreach (var section_name in profile.Sections.Keys)
                {
                    // Copy Entries in this Section
                    entries[i] = new string[profile.Sections[section_name].Entries.Count][];
                    var j = 0;
                    foreach (var key in profile.Sections[section_name].Entries.Keys)
                    {
                        // for Entry
                        entries[i][j++] = new string[] { key, profile.Sections[section_name].Entries[key] };
                    }
                    i++;
                }

                // RETURN
                return(new object[]
                {
                    section_names,
                    entries,
                    profile.GetRawLines()
                });
            }
Exemple #2
0
        // ----------------------------------------------------------------
        // Utilities
        // ----------------------------------------------------------------

        // Print Profile
        public static void PrintProfile(PrivateProfile profile)
        {
            // Print Information: Null Section, Print Number of Sections, and so on...
            Console.WriteLine($"FileName = " + (profile.FileName is null ? "(null)" : $"\"{profile.FileName}\""));
            Console.WriteLine($"IsOpen = {profile.IsOpen}");
            Console.WriteLine($"IsReadOnly = {profile.IsReadOnly}");
            Console.WriteLine($"IsUpdated = {profile.IsUpdated}");
            Console.WriteLine($"Number of Sections = {profile.Sections.Count}");

            // Section Names
            var i = 0;

            foreach (var section_name in profile.Sections.Keys)
            {
                Console.WriteLine($"Sections[{i++}] Name = \"{profile.Sections[section_name].Name}\"");

                // Entries
                var j = 0;
                foreach (var key in profile.Sections[section_name].Entries.Keys)
                {
                    Console.WriteLine("    Entries[{0}][{1}] (Key, Value) = (\"{2}\", \"{3}\")", i, j++,
                                      key, (profile.Sections[section_name].Entries[key] is null ? "null" : $"\"{profile.Sections[section_name].Entries[key]}\""));
                }
            }

            // Raw Lines
            var k = 0;

            foreach (var line in profile.GetRawLines())
            {
                Console.WriteLine($"Raw Lines[{k++}] = \"{line}\"");
            }

            // Print Blank Line
            Console.WriteLine();
        }