ConfigFile.Load C# (CSharp) Method

Load() public method

public Load ( Stream ms ) : bool
ms Stream
return bool
    public bool Load(Stream ms)
    {
        StreamReader sr = new StreamReader(ms);
        return parse(sr);
    }

Same methods

ConfigFile::Load ( byte buff ) : bool
ConfigFile::Load ( string path ) : bool

Usage Example

Example #1
0
        /// <summary>
        /// Go through our media/wheels/ directory and find all of the wheel definitions we have, then make dictionaries out of them
        /// and add them to our one big dictionary.		
        /// </summary>
        public void ReadWheelsFromFiles()
        {
            // since we can run this whenever (like when we're tweaking files), we want to clear our dictionary first
            wheels.Clear();

            // get all of the filenames of the files in media/wheels/
            IEnumerable<string> files = Directory.EnumerateFiles("media/vehicles/", "*.wheel", SearchOption.AllDirectories);

            foreach (string filename in files) {
                // I forgot ogre had this functionality already built in
                ConfigFile cfile = new ConfigFile();
                cfile.Load(filename, "=", true);

                // each .wheel file can have multiple [sections]. We'll use each section name as the wheel name
                ConfigFile.SectionIterator sectionIterator = cfile.GetSectionIterator();
                while (sectionIterator.MoveNext()) {
                    string wheelname = sectionIterator.CurrentKey;
                    // make a dictionary
                    var wheeldict = new Dictionary<string, float>();
                    // go over every property in the file and add it to the dictionary, parsing it as a float
                    foreach (KeyValuePair<string, string> pair in sectionIterator.Current) {
                        wheeldict.Add(pair.Key, float.Parse(pair.Value, culture));
                    }

                    wheels[wheelname] = wheeldict;
                }

                cfile.Dispose();
                sectionIterator.Dispose();
            }
        }
All Usage Examples Of ConfigFile::Load