本文整理汇总了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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例5: ConfigNode
public ConfigNode(string name, TextReader reader)
{
_name = name;
_data = new Hashtable();
_childConfigNodes = new ArrayList();
ReadFrom(reader);
}
示例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);
}
示例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;
}
示例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;
}
示例9: IsWellFormed
public static XmlDocument IsWellFormed(TextReader reader)
{
Assert.IsNotNull(reader);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return doc;
}
示例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;
}
示例11: LoadFromTextReader
public static YamlNode LoadFromTextReader(TextReader reader)
{
var yaml = new YamlStream();
yaml.Load(reader);
return yaml.Documents.First().RootNode;
}
示例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");
}
示例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);
}
示例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));
}
示例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;
}