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


C# IO.TextReader类代码示例

本文整理汇总了C#中System.IO.TextReader的典型用法代码示例。如果您正苦于以下问题:C# TextReader类的具体用法?C# TextReader怎么用?C# TextReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TextReader类属于System.IO命名空间,在下文中一共展示了TextReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MigrateUsingXslt

		protected static void MigrateUsingXslt(TextReader xslStream, TextReader xmlStream, string destinationFilePath)
		{
			var transform = new XslCompiledTransform();
			using (xslStream)
			{
				using (xmlStream)
				{
					using (var destinationStream = new StreamWriter(destinationFilePath))
					{
						var xslReader = XmlReader.Create(xslStream);
						transform.Load(xslReader);
						xslReader.Close();
						xslStream.Close();

						var reader = XmlReader.Create(xmlStream);

						var settings = new XmlWriterSettings { Indent = true };
						var writer = XmlWriter.Create(destinationStream, settings);

						transform.Transform(reader, writer);

						var tempfiles = transform.TemporaryFiles;
						if (tempfiles != null) // tempfiles will be null when debugging is not enabled
						{
							tempfiles.Delete();
						}
						writer.Close();
						reader.Close();
						destinationStream.Close();
					}
					xmlStream.Close();
				}
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:34,代码来源:XslMigrationStrategy.cs

示例2: Read

        public RecentComputerList Read( TextReader reader )
        {
            RecentComputerList computers = new RecentComputerList();

            while ( true )
            {
                string line = reader.ReadLine();
                if ( line == null )
                    break;

                string[] pair = line.Split( '\t' );

                // Avoid processing an empty line
                if ( pair[0] == "" )
                    continue;
                string computer = pair[0];

                string alias = pair.Length > 1 ? pair[1] : "";

                bool adminMode = false;
                if ( pair.Length > 2 )
                    bool.TryParse( pair[2], out adminMode );

                computers.Add( new ComputerName( computer, alias, adminMode ) );
            }

            return computers;
        }
开发者ID:rajeshwarn,项目名称:RemoteDesktopPlus,代码行数:28,代码来源:ComputerListFile.cs

示例3: ParseJIL

        public JobDefinition ParseJIL(TextReader instr)
        {
            JobDefinition jobdef = new JobDefinition();

            char[] delim = {':'};
            string [] keyval = new string[2];
            string jil;

            Regex rx = new Regex("[A-Za-z-_]+:.*"); // Looks like a JIL key/value pair

            while ( (jil = instr.ReadLine()) != null )
            {
                if (rx.IsMatch(jil))
                {
                    keyval = jil.Split(delim, 2);
                    jobdef.SetField(keyval[0], keyval[1]);
                }
                else
                {
                    Console.Error.WriteLine("Warning: Malformed JIL encountered and ignored: {0}", jil);
                }
            }

            return jobdef;
        }
开发者ID:dugoh,项目名称:advancedscheduler,代码行数:25,代码来源:AdvancedScheduler.cs

示例4: StreamInfoProvider

        /// <summary>
        /// Provide as much information about the input stream as we can,  size
        /// and position
        /// </summary>
        /// <param name="reader">reader we are analysing</param>
        public StreamInfoProvider(TextReader reader)
        {
            if (reader is StreamReader)
            {
                var stream = ((StreamReader)reader).BaseStream;
                mLength = stream.Length;
                // Uses the buffer position
                mPositionCalculator = () => stream.Position;
            }
            else if (reader is InternalStreamReader)
            {
                var reader2 = ((InternalStreamReader)reader);
                var stream = reader2.BaseStream;

                mLength = stream.Length;
                // Real Position
                mPositionCalculator = () => reader2.Position;
            }
            else if (reader is InternalStringReader)
            {
                var stream = (InternalStringReader)reader;
                mLength = stream.Length;
                mPositionCalculator = () => stream.Position;
            }
        }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:30,代码来源:StreamInfoProvider.cs

示例5: ConfigNode

 public ConfigNode(string name, TextReader reader)
 {
     _name = name;
     _data = new Hashtable();
     _childConfigNodes = new ArrayList();
     ReadFrom(reader);
 }
开发者ID:rfyiamcool,项目名称:solrex,代码行数:7,代码来源:ConfigParser.cs

示例6: Template

        public static void Template(TextReader reader, object data, TextWriter writer, RenderContextBehaviour renderContextBehaviour = null)
        {
            var renderBehaviour = renderContextBehaviour ??
                                        RenderContextBehaviour.GetDefaultRenderContextBehaviour();

            Template(reader, data, writer, null, renderBehaviour);
        }
开发者ID:Romanx,项目名称:Nustache,代码行数:7,代码来源:Render.cs

示例7: ReadVerBarConfig

        public static KeyValueConfig ReadVerBarConfig(TextReader reader)
        {
            var result = new KeyValueConfig();
            string line;

            int lineNum = 0;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(new char[] {'|'});

                if (lineNum == 0) // keys
                {
                    foreach (var token in tokens)
                    {
                        var tokens2 = token.Split(new char[] {'!'});
                        result.Data[tokens2[0]] = new List<string>();
                    }
                }
                else // values
                {
                    //if (Data.Count != tokens.Length)
                    //    throw new Exception("VerBarConfig: Data.Count != tokens.Length");
                    if (result.Data.Count != tokens.Length)
                        continue;

                    for (int i = 0; i < result.Data.Count; i++)
                        result.Data.ElementAt(i).Value.Add(tokens[i]);
                }

                lineNum++;
            }

            return result;
        }
开发者ID:Ser0ja,项目名称:CASCExplorer,代码行数:35,代码来源:CASCConfig.cs

示例8: Load

        public DatabaseVersionSetup Load(TextReader reader)
        {
            var versionSetup = new DatabaseVersionSetup();

            var shemas = new XmlSchemaSet();
            Assembly assem = typeof(DatabaseVersionSetup).Assembly;
            using (Stream stream = assem.GetManifestResourceStream("DatabaseVersionControl.Core.Xsd.DVCSchema.xsd"))
            {
                if (stream != null){
                    shemas.Add("", XmlReader.Create(stream));
                }
                else{
                    throw new Exception("Could not load embedded resource Xsd.DVCSchema.xsd");
                }
            }
            XDocument element = XDocument.Load(reader);
            element.Validate(shemas, (sender, e) =>
                                         { if (_exception != null) _exception(e); }, true);
            var profiles = element.XPathSelectElements("//profiles/profile");
            versionSetup.DefaultProfile = element.Root.Attribute("defaultProfile").Value;
            LoadProfiles(versionSetup, profiles);
            var databases = element.XPathSelectElements("//repositories/repository");
            LoadRepositories(versionSetup, databases);
            return versionSetup;
        }
开发者ID:rolfwessels,项目名称:databaseversioncontrol,代码行数:25,代码来源:XmlConfigFileLoader.cs

示例9: IsWellFormed

 public static XmlDocument IsWellFormed(TextReader reader)
 {
     Assert.IsNotNull(reader);
     XmlDocument doc = new XmlDocument();
     doc.Load(reader);
     return doc;
 }
开发者ID:buptkang,项目名称:QuickGraph,代码行数:7,代码来源:XmlAssert.cs

示例10: ParseText

        public List<string> ParseText(TextReader pReader)
        {
            result.Clear();

            int	count = 0;
            do
            {
                count = pReader.ReadBlock(buffer, 0, BUFFER_SIZE);
                for (int i = 0; i < count; ++i)
                {
                    char c = buffer[i];
                    if (char.IsWhiteSpace(c))
                    {
                        ParseWhitespace();
                    }
                    else if (Contains(punctuation, c))
                    {
                        ParsePunctuation(c);
                    }
                    else if (char.IsLetterOrDigit(c))
                    {
                        ParseLetter(c);
                    }else{
                        ParseLetter(c);
                    }
                }

            } while(count == BUFFER_SIZE);
            return result;
        }
开发者ID:substans,项目名称:MarkovChainFoolery,代码行数:30,代码来源:WordTokenizer.cs

示例11: LoadFromTextReader

		public static YamlNode LoadFromTextReader(TextReader reader)
		{
			var yaml = new YamlStream();
			yaml.Load(reader);

			return yaml.Documents.First().RootNode;
		}
开发者ID:adbrowne,项目名称:EventStore,代码行数:7,代码来源:YamlDoc.cs

示例12: Answer

        public static void Answer(TextReader reader)
        {
            int n = Convert.ToInt32(reader.ReadLine());
            int[] coordinates = reader.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            List<Line> lines = new List<Line>();

            for (int index = 0; index < coordinates.Length - 1; index++)
            {
                int a = coordinates[index];
                int b = coordinates[index + 1];
                lines.Add(new Line {From = Math.Min(a,b), To = Math.Max(a,b)});
            }

            for (int i = 0; i < lines.Count; i++)
            {
                for(int j = 0; j< lines.Count; j++)
                {
                    if (intersect(lines[i], lines[j]))
                    {
                        Console.WriteLine("yes");
                        return;
                    }
                }
            }
            Console.WriteLine("no");
        }
开发者ID:john0xff,项目名称:algorithms,代码行数:26,代码来源:DimaAndContinuousLine.cs

示例13: GetKnapsack

        public static Knapsack GetKnapsack(TextReader reader)
        {
            Contract.Requires<ArgumentNullException>(reader != null, "reader");
            var firstRow = reader.ReadLine();
            var firtsRowParts = firstRow.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int capacity = int.Parse(firtsRowParts[0]);
            int numberOfItems = int.Parse(firtsRowParts[1]);

            var items = new List<KnapsackItem>(numberOfItems);
            while (true)
            {
                string row = reader.ReadLine();
                if (row == null)
                {
                    break;
                }

                var parts = row.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                var parameters = parts.Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();

                items.Add(new KnapsackItem(parameters[0], parameters[1]));
            }

            return new Knapsack(items, capacity);
        }
开发者ID:korzenikov,项目名称:Projects,代码行数:25,代码来源:KnapsackReader.cs

示例14: Parse

        /// <summary>
        /// Parse and filter the supplied modifications.  The position of each modification in the list is used as the ChangeNumber.
        /// </summary>
        /// <param name="history"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public Modification[] Parse(TextReader history, DateTime from, DateTime to)
        {
            StringReader sr = new StringReader(string.Format(@"<ArrayOfModification xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">{0}</ArrayOfModification>"
                , history.ReadToEnd()));

            XmlSerializer serializer = new XmlSerializer(typeof(Modification[]));
            Modification[] mods;
            try
            {
                mods = (Modification[])serializer.Deserialize(sr);
            }
            catch (Exception ex)
            {
                throw new CruiseControlException("History Parsing Failed", ex);
            }

            ArrayList results = new ArrayList();
            int change = 0;
            foreach (Modification mod in mods)
            {
                change++;
                mod.ChangeNumber = change;
                if ((mod.ModifiedTime >= from) & (mod.ModifiedTime <= to))
                {
                    results.Add(mod);
                }
            }
            return (Modification[])results.ToArray(typeof(Modification));
        }
开发者ID:MsPenghao,项目名称:ccnet.git.plugin,代码行数:36,代码来源:gitHistoryParser.cs

示例15: Read

        /// <summary>Read in rating data from a TextReader</summary>
        /// <param name="reader">the <see cref="TextReader"/> to read from</param>
        /// <param name="user_mapping">mapping object for user IDs</param>
        /// <param name="item_mapping">mapping object for item IDs</param>
        /// <returns>the rating data</returns>
        public static ITimedRatings Read(TextReader reader, IEntityMapping user_mapping = null, IEntityMapping item_mapping = null)
        {
            if (user_mapping == null)
                user_mapping = new IdentityMapping();
            if (item_mapping == null)
                item_mapping = new IdentityMapping();

            var ratings = new TimedRatings();

            string[] separators = { "::" };
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(separators, StringSplitOptions.None);

                if (tokens.Length < 4)
                    throw new FormatException(string.Format("Expected at least 4 columns: {0}", line));

                int user_id = user_mapping.ToInternalID(tokens[0]);
                int item_id = item_mapping.ToInternalID(tokens[1]);
                float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
                long seconds = uint.Parse(tokens[3]);

                var time = new DateTime(seconds * 10000000L).AddYears(1969);
                var offset = TimeZone.CurrentTimeZone.GetUtcOffset(time);
                time -= offset;

                ratings.Add(user_id, item_id, rating, time);
            }
            return ratings;
        }
开发者ID:kinyue,项目名称:MyMediaLite,代码行数:37,代码来源:MovieLensRatingData.cs


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