本文整理汇总了C#中System.IO.TextReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.Dispose方法的具体用法?C# TextReader.Dispose怎么用?C# TextReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpgradesComparison
public UpgradesComparison(TextReader reader)
{
InitializeComponent();
MainPage.Instance.UpgradeListOpen = true;
Graph.Mode = ComparisonGraph.DisplayMode.Overall;
Graph.Character = MainPage.Instance.Character;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(SerializationData));
SerializationData data = (SerializationData)serializer.Deserialize(reader);
SetCustomSubpoints(data.CustomSubpoints);
itemCalculations = new Dictionary<string, ComparisonCalculationUpgrades[]>();
for (int i = 0; i < data.Keys.Count; i++)
{
itemCalculations[data.Keys[i]] = data.ItemCalculations[i];
}
SlotCombo.SelectedIndex = 0;
}
catch (Exception /*e*/)
{
Close();
MessageBox.Show("The chosen file is not a Rawr Upgrade List.", "Unable to Load Upgrade List", MessageBoxButton.OK);
}
finally { reader.Dispose(); }
}
示例2: process
public List<Token> process(TextReader textReader)
{
Debug.Assert(textReader != null);
m_tokens = new List<Token>();
m_textReader = textReader;
m_endOfFile = false;
readNextChar();
m_currentLine = 1;
m_currentPosition = 0;
m_currentTokenStartPosition = 0;
Token t;
do {
t = readNextToken();
t.LineNr = m_currentLine;
t.LinePosition = m_currentTokenStartPosition;
m_currentTokenStartPosition = m_currentPosition;
m_tokens.Add(t);
//Console.WriteLine(t.LineNr + ": " + t.getTokenType().ToString() + " " + t.getTokenString());
} while(t.getTokenType() != Token.TokenType.EOF);
m_textReader.Close();
m_textReader.Dispose();
return m_tokens;
}
示例3: process
public List<Token> process(TextReader pTextReader)
{
D.isNull(pTextReader);
_tokens = new List<Token>();
_textReader = pTextReader;
_endOfFile = false;
readNextChar();
_currentLine = 1;
_currentPosition = 0;
_currentTokenStartPosition = 0;
Token t;
do {
t = readNextToken();
t.LineNr = _currentLine;
t.LinePosition = _currentTokenStartPosition;
_currentTokenStartPosition = _currentPosition;
_tokens.Add(t);
#if WRITE_DEBUG
Console.WriteLine(t.LineNr + ": " + t.getTokenType().ToString() + " " + t.getTokenString());
#endif
} while(t.getTokenType() != Token.TokenType.EOF);
_textReader.Close();
_textReader.Dispose();
return _tokens;
}
示例4: Normalize
public static TextReader Normalize(TextReader tr, ISerializationContext ctx)
{
string s = tr.ReadToEnd();
TextReader reader = Normalize(s, ctx);
tr.Dispose();
return reader;
}
示例5: TestNullTextReader
public static void TestNullTextReader(TextReader input)
{
StreamReader sr = input as StreamReader;
if (sr != null)
Assert.True(sr.EndOfStream, "EndOfStream property didn't return true");
input.ReadLine();
input.Dispose();
input.ReadLine();
if (sr != null)
Assert.True(sr.EndOfStream, "EndOfStream property didn't return true");
input.Read();
input.Peek();
input.Read(new char[2], 0, 2);
input.ReadToEnd();
input.Dispose();
}
示例6: displayData
private void displayData(TextReader reader)
{
source.Text = "";
string line = reader.ReadLine();
while (line != null)
{
source.Text += line + '\n';
line = reader.ReadLine();
}
reader.Dispose();
}
示例7: XmlClientConfigBuilder
internal XmlClientConfigBuilder(TextReader reader)
{
try
{
_document.Load(reader);
reader.Dispose();
}
catch (Exception)
{
throw new InvalidOperationException("Could not parse configuration file, giving up.");
}
}
示例8: SettingsFileManager
public SettingsFileManager(string filename)
{
InitializeDefaultSettings();
settings = new Dictionary<Settings, string>();
try
{
reader = new StreamReader(filename);
}
catch (FileNotFoundException)
{
File.Create(filename);
reader = new StreamReader(filename);
}
bool endReached = false;
List<string> lines = new List<string>();
while (!endReached)
{
string line = reader.ReadLine();
if (line == null)
{
endReached = true;
}
else
{
lines.Add(line);
}
}
reader.Close();
reader.Dispose();
foreach (string line in lines)
{
// Ignore comments
if(line.StartsWith("//")) continue;
// Split string into key and value
string[] linePieces = line.Split('=');
if (1< linePieces.Length && linePieces.Length <3)
{
// Turn the first argument into an enum constant
Settings s = (Settings)Enum.Parse(typeof(Settings), linePieces[0].ToUpper(), true);
settings.Add(s, linePieces[1]);
}
}
}
示例9: ODataJsonInputContext
internal ODataJsonInputContext(ODataFormat format, TextReader reader, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, bool readingResponse, bool synchronous, IEdmModel model, IODataUrlResolver urlResolver) : base(format, messageReaderSettings, version, readingResponse, synchronous, model, urlResolver)
{
ExceptionUtils.CheckArgumentNotNull<ODataFormat>(format, "format");
ExceptionUtils.CheckArgumentNotNull<ODataMessageReaderSettings>(messageReaderSettings, "messageReaderSettings");
try
{
this.textReader = reader;
this.jsonReader = new BufferingJsonReader(this.textReader, base.UseServerFormatBehavior, messageReaderSettings.MessageQuotas.MaxNestingDepth);
}
catch (Exception exception)
{
if (ExceptionUtils.IsCatchableExceptionType(exception) && (reader != null))
{
reader.Dispose();
}
throw;
}
}
示例10: Parse
public override void Parse(TextReader @in)
{
int lineNumber = 0;
try
{
string line = null;
while ((line = @in.ReadLine()) != null)
{
lineNumber++;
if (line.Length == 0 || line[0] == '#')
{
continue; // ignore empty lines and comments
}
CharsRef[] inputs;
CharsRef[] outputs;
// TODO: we could process this more efficiently.
string[] sides = Split(line, "=>");
if (sides.Length > 1) // explicit mapping
{
if (sides.Length != 2)
{
throw new System.ArgumentException("more than one explicit mapping specified on the same line");
}
string[] inputStrings = Split(sides[0], ",");
inputs = new CharsRef[inputStrings.Length];
for (int i = 0; i < inputs.Length; i++)
{
inputs[i] = Analyze(Unescape(inputStrings[i]).Trim(), new CharsRef());
}
string[] outputStrings = Split(sides[1], ",");
outputs = new CharsRef[outputStrings.Length];
for (int i = 0; i < outputs.Length; i++)
{
outputs[i] = Analyze(Unescape(outputStrings[i]).Trim(), new CharsRef());
}
}
else
{
string[] inputStrings = Split(line, ",");
inputs = new CharsRef[inputStrings.Length];
for (int i = 0; i < inputs.Length; i++)
{
inputs[i] = Analyze(Unescape(inputStrings[i]).Trim(), new CharsRef());
}
if (expand)
{
outputs = inputs;
}
else
{
outputs = new CharsRef[1];
outputs[0] = inputs[0];
}
}
// currently we include the term itself in the map,
// and use includeOrig = false always.
// this is how the existing filter does it, but its actually a bug,
// especially if combined with ignoreCase = true
for (int i = 0; i < inputs.Length; i++)
{
for (int j = 0; j < outputs.Length; j++)
{
Add(inputs[i], outputs[j], false);
}
}
}
}
catch (System.ArgumentException e)
{
throw new Exception("Invalid synonym rule at line " + lineNumber, e);
//ex.initCause(e);
//throw ex;
}
finally
{
@in.Dispose();
}
}
示例11: ODataJsonLightInputContext
internal ODataJsonLightInputContext(
ODataFormat format,
TextReader reader,
ODataMediaType contentType,
ODataMessageReaderSettings messageReaderSettings,
bool readingResponse,
bool synchronous,
IEdmModel model,
IODataUrlResolver urlResolver)
: base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
{
Debug.Assert(reader != null, "reader != null");
Debug.Assert(contentType != null, "contentType != null");
try
{
ExceptionUtils.CheckArgumentNotNull(format, "format");
ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");
}
catch (ArgumentNullException)
{
// Dispose the message stream if we failed to create the input context.
reader.Dispose();
throw;
}
try
{
this.textReader = reader;
if (contentType.HasStreamingSetToTrue())
{
this.jsonReader = new BufferingJsonReader(
this.textReader,
JsonLightConstants.ODataErrorPropertyName,
messageReaderSettings.MessageQuotas.MaxNestingDepth,
ODataFormat.Json,
contentType.HasIeee754CompatibleSetToTrue());
}
else
{
// If we have a non-streaming Json Light content type we need to use the re-ordering Json reader
this.jsonReader = new ReorderingJsonReader(this.textReader, messageReaderSettings.MessageQuotas.MaxNestingDepth, contentType.HasIeee754CompatibleSetToTrue());
}
}
catch (Exception e)
{
// Dispose the message stream if we failed to create the input context.
if (ExceptionUtils.IsCatchableExceptionType(e) && reader != null)
{
reader.Dispose();
}
throw;
}
// dont know how to get MetadataDocumentUri uri here, messageReaderSettings do not have one
// Uri metadataDocumentUri = messageReaderSettings..MetadataDocumentUri == null ? null : messageReaderSettings.MetadataDocumentUri.BaseUri;
// the uri here is used here to create the FullMetadataLevel can pass null in
this.metadataLevel = JsonLight.JsonLightMetadataLevel.Create(contentType, null, model, readingResponse);
}
示例12: transactions
//.........这里部分代码省略.........
}
finally
{
}
}
}
finally
{
}
if (doWplaty < 0)
{
goto DEPOSIT;
}
// Zaktualizuj bankroll , endDate , bankrollTo, startingAvarageIncome
// Wczytaj pierwszą linię
string pierwszaLinijka = "";
string reszta = "";
try
{
textReader = new StreamReader(fileName);
}
catch (Exception e) { }
finally
{
pierwszaLinijka = textReader.ReadLine();
reszta = textReader.ReadToEnd();
textReader.Dispose();
textReader.Close();
}
// Wczytać resztę komendą readToEnd
// Zmienić br ,ed ,brT, sai
bankroll += doWplaty;
bankrollTo = bankroll * (1 + expectedMonthlyIncome);
endDate = DateTime.Today.AddMonths(1);
int howManyDaLeft;
if (endDate.Year == DateTime.Now.Year)
{
howManyDaLeft = endDate.DayOfYear - DateTime.Now.DayOfYear;
startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft;
}
else
{
howManyDaLeft = (daysInYear(DateTime.Now.Year) - DateTime.Now.DayOfYear) + endDate.DayOfYear;
startingAvarageIncome = (bankrollTo - bankroll) / howManyDaLeft;
}
// Zmienić pierwszą linię
// Zapisać all
try
{
textWriter = new StreamWriter(fileName);
}
catch (Exception e) { }
finally
{
示例13: Deserialize
public override object Deserialize(TextReader tr)
{
if (tr != null)
{
// Normalize the text before parsing it
tr = TextUtil.Normalize(tr, SerializationContext);
// Create a lexer for our text stream
iCalLexer lexer = new iCalLexer(tr);
iCalParser parser = new iCalParser(lexer);
// Get our serialization context
ISerializationContext ctx = SerializationContext;
// Parse the component!
ICalendarProperty p = parser.property(ctx, null);
// Close our text stream
tr.Dispose();
// Return the parsed property
return p;
}
return null;
}
示例14: history
private void history()
{
int ileZakladow = 0;
int ileLinijek = 0;
int ilePokazac = 0;
try
{
textReader = new StreamReader(fileName);
}
catch (Exception e) { }
finally
{
s = textReader.ReadLine();
while (s != null)
{
ileLinijek++;
ileZakladow++;
s = textReader.ReadLine();
}
ileZakladow--;
textReader.Dispose();
textReader.Close();
}
string[] wszystkieLinijki = new string[ileZakladow+1];
try
{
textReader = new StreamReader(fileName);
}
catch (Exception e) { }
finally
{
int i = 0;
s = textReader.ReadLine();
while (s != null)
{
wszystkieLinijki[i] = s;
i++;
s = textReader.ReadLine();
}
textReader.Dispose();
textReader.Close();
}
Console.Write("Masz w historii ");
Console.ForegroundColor = ConsoleColor.Cyan;
if (checkIfHavePendingBets()) { ileZakladow--; }
Console.Write(ileZakladow);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(" zakładów");
Console.Write("\n\nWpisz ile ostatnich zakładów chcesz zobaczyć, 0 aby wyjść ( liczba musi być mniejsza od ilości zakładów ): ");
Console.Write("\n-> ");
s = Console.ReadLine();
try
{
ilePokazac = int.Parse(s);
}
catch (Exception e) { ilePokazac = 0; }
finally { }
if (ilePokazac <= 0 || ilePokazac > ileZakladow)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("\nPodano złą liczbę zakładów!");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\n\nKliknij ENTER aby wrócić do Menu...");
if (Console.ReadLine() != "EXIT")
{
}
}
else
{
if (ilePokazac < 33)
{
Console.BufferHeight = 40;
}
else if (ilePokazac >= 33 && ilePokazac < int.MaxValue - 8)
{
Console.BufferHeight = ilePokazac + 7;
}
else
{
Console.BufferHeight = int.MaxValue - 1;
}
//.........这里部分代码省略.........
示例15: ToString
/// <summary>
/// Reads until end-of-stream and returns all read chars, finally closes the stream.
/// </summary>
/// <param name="input"> the input stream </param>
/// <exception cref="IOException"> if an I/O error occurs while reading the stream </exception>
private static string ToString(TextReader input)
{
var reader = input as FastStringReader;
if (reader != null) // fast path
{
return reader.String;
}
try
{
int len = 256;
char[] buffer = new char[len];
char[] output = new char[len];
len = 0;
int n;
while ((n = input.Read(buffer)) >= 0)
{
if (len + n > output.Length) // grow capacity
{
char[] tmp = new char[Math.Max(output.Length << 1, len + n)];
Array.Copy(output, 0, tmp, 0, len);
Array.Copy(buffer, 0, tmp, len, n);
buffer = output; // use larger buffer for future larger bulk reads
output = tmp;
}
else
{
Array.Copy(buffer, 0, output, len, n);
}
len += n;
}
return new string(output, 0, len);
}
finally
{
input.Dispose();
}
}