示例#1
0
文件: Topology.cs 项目: pulsence/ENN
        /// <summary>
        /// Strips out the raw types from the file and prepares them for being parsed
        /// into objects.
        /// </summary>
        /// <param name="file">Location of the file to open.</param>
        /// <returns>Returns a list of raw types found in the file.</returns>
        /// <exception cref="IOException">System.IO.IOException</exception>
        private static List<RawType> GetRawTypes(string file)
        {
            StreamReader fs = File.OpenText(file);

            //Used when triming the end of a line that starts a type
            string newLine = " \t\n{";
            string line;
            string[] splitLine;
            List<RawType> rawTypes = new List<RawType>();
            RawType rawType = new RawType();
            bool openFound = false;
            while (!fs.EndOfStream)
            {
                line = fs.ReadLine();
                line = line.Trim();

                //skip commented or empty lines;
                if (line.StartsWith("#") || line == "") continue;

                //check for the start of a type
                if (!openFound)
                {
                    if (line[line.Length - 1] == '{')
                    {
                        line = line.Trim(newLine.ToCharArray());
                        rawType.Type = line;
                        openFound = true;
                    }
                }
                else if (line[0] == '}')//check for the closing of a type
                {
                    openFound = false;
                    rawTypes.Add(rawType);
                    rawType = new RawType();
                }
                else if (openFound)//addes the fields if a type has be opened
                {
                    splitLine = line.Split(':');
                    rawType.Fields.Add(splitLine[0].Trim(), splitLine[1].Trim());
                }
                else
                {
                    splitLine = line.Split(':');
                    splitLine[0] = splitLine[0].Trim();
                    splitLine[1] = splitLine[1].Trim();

                    //checks to see if there is an include file command
                    if (splitLine[0] == "include")
                    {
                        rawTypes.AddRange(GetRawTypes(splitLine[1]));
                    }
                }
            }

            fs.Close();
            return rawTypes;
        }
示例#2
0
文件: Topology.cs 项目: pulsence/ENN
        /// <summary>
        /// Strips out the raw types from the file and prepares them for being parsed
        /// into objects.
        /// </summary>
        /// <param name="file">Location of the file to open.</param>
        /// <returns>Returns a list of raw types found in the file.</returns>
        /// <exception cref="IOException">System.IO.IOException</exception>
        private static List <RawType> GetRawTypes(string file)
        {
            StreamReader fs = File.OpenText(file);

            //Used when triming the end of a line that starts a type
            string newLine = " \t\n{";
            string line;

            string[]       splitLine;
            List <RawType> rawTypes  = new List <RawType>();
            RawType        rawType   = new RawType();
            bool           openFound = false;

            while (!fs.EndOfStream)
            {
                line = fs.ReadLine();
                line = line.Trim();

                //skip commented or empty lines;
                if (line.StartsWith("#") || line == "")
                {
                    continue;
                }

                //check for the start of a type
                if (!openFound)
                {
                    if (line[line.Length - 1] == '{')
                    {
                        line         = line.Trim(newLine.ToCharArray());
                        rawType.Type = line;
                        openFound    = true;
                    }
                }
                else if (line[0] == '}')                //check for the closing of a type
                {
                    openFound = false;
                    rawTypes.Add(rawType);
                    rawType = new RawType();
                }
                else if (openFound)                //addes the fields if a type has be opened
                {
                    splitLine = line.Split(':');
                    rawType.Fields.Add(splitLine[0].Trim(), splitLine[1].Trim());
                }
                else
                {
                    splitLine    = line.Split(':');
                    splitLine[0] = splitLine[0].Trim();
                    splitLine[1] = splitLine[1].Trim();

                    //checks to see if there is an include file command
                    if (splitLine[0] == "include")
                    {
                        rawTypes.AddRange(GetRawTypes(splitLine[1]));
                    }
                }
            }

            fs.Close();
            return(rawTypes);
        }