当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.ReadFields方法代码示例

本文整理汇总了C#中Microsoft.ReadFields方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.ReadFields方法的具体用法?C# Microsoft.ReadFields怎么用?C# Microsoft.ReadFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft的用法示例。


在下文中一共展示了Microsoft.ReadFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoSecondPass

        internal void DoSecondPass(StreamReader reader, Microsoft.VisualBasic.FileIO.TextFieldParser parser, IBasicAdjList network)
        {
            // now, the network had been created based on the headers of each section, the list of
            // header fields has been populated for each section, nodes have been created.
            // so populate the node data, create the edges, and populate edge data

            // 1) read line
            // 2) if line is a '*' line
            //      read line and set state, skip next line
            //  3) read items based on state
            int index = 0;
            string line = null;
            string[] fields = null;
            try
            {
                while (!parser.EndOfData)
                {
                    if (parser.PeekChars(1) == "*")
                    {
                        line = parser.ReadLine();
                        State = ReadStarLine(line);
                        // skip the header line
                        parser.ReadLine();
                        // reset the index at each * section
                        index = 0;
                        continue;
                    }

                    // if here, then it is not a header line or star line
                    fields = Clean(parser.ReadFields());
                    switch (State)
                    {
                        case VnaFileSection.NodeData:
                            ReadNodeDataFields(fields, network, index++, NodeDataHeaders);
                            break;
                        case VnaFileSection.NodeProperties:
                            ReadNodePropertyFields(fields, network, index++, NodePropertyHeaders);
                            break;
                        case VnaFileSection.EdgeData:
                            ReadEdgeDataFields(fields, network, EdgeDataHeaders);
                            break;
                        case VnaFileSection.EdgeProperties:
                            ReadEdgePropertyFields(fields, network, index++, EdgePropertyHeaders);
                            break;
                        default:
                            throw new InvalidOperationException(string.Format("{0} is an invalid state", State));
                    }
                }
            }
            catch (FormatException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A format error occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch(NullReferenceException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A null value occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("An error occurred while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:71,代码来源:VnaAdjListReader.cs

示例2: DoFirstPass

        internal void DoFirstPass(TextReader reader, Microsoft.VisualBasic.FileIO.TextFieldParser parser, out int nodeCount, out int edgeCount)
        {
            string mssg = null;
            nodeCount = 0;
            edgeCount = 0;
            string line = null;
            string[] fields = null;
            try
            {
                while (!parser.EndOfData)
                {
                    if (parser.PeekChars(1) == "*")
                    {
                        line = parser.ReadLine();
                        State = ReadStarLine(line);
                        // next line is header
                        fields = Clean(parser.ReadFields());
                        if (ValidateHeaderFields(fields, State, out mssg))
                            ReadHeaders(fields, State);
                        else
                        {
                            ErrorMessages.Add(mssg);
                            break;
                        }
                        continue;
                    }

                    line = parser.ReadLine();
                    // if here, then it is not a header line or star line
                    switch (State)
                    {
                        case VnaFileSection.NodeData:
                            nodeCount++;
                            break;
                        case VnaFileSection.EdgeData:
                            edgeCount++;
                            break;
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A null value occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("An error occurred while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:55,代码来源:VnaAdjListReader.cs


注:本文中的Microsoft.ReadFields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。