本文整理匯總了C#中System.IO.StringReader.RemoveFromEnd方法的典型用法代碼示例。如果您正苦於以下問題:C# StringReader.RemoveFromEnd方法的具體用法?C# StringReader.RemoveFromEnd怎麽用?C# StringReader.RemoveFromEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.RemoveFromEnd方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadStringLiteral
/// <summary>
/// Reads string-literal(stores it to reader 'r') and continuing fetch line.
/// </summary>
/// <param name="imap">IMAP client.</param>
/// <param name="r">String reader.</param>
/// <param name="callback">Fetch completion callback.</param>
/// <returns>Returns true if completed asynchronously or false if completed synchronously.</returns>
/// <exception cref="ArgumentNullException">Is raised when <b>imap</b>,<b>r</b> or <b>callback</b> is null reference.</exception>
private bool ReadStringLiteral(IMAP_Client imap,StringReader r,EventHandler<EventArgs<Exception>> callback)
{
if(imap == null){
throw new ArgumentNullException("imap");
}
if(r == null){
throw new ArgumentNullException("r");
}
if(callback == null){
throw new ArgumentNullException("callback");
}
if(r.SourceString.EndsWith("}") && r.SourceString.IndexOf("{") > -1){
MemoryStream stream = new MemoryStream();
string size = r.SourceString.Substring(r.SourceString.LastIndexOf("{") + 1,r.SourceString.Length - r.SourceString.LastIndexOf("{") - 2);
// Remove {n} from string.
r.RemoveFromEnd(r.SourceString.Length - r.SourceString.LastIndexOf('{'));
IMAP_Client.ReadStringLiteralAsyncOP op = new IMAP_Client.ReadStringLiteralAsyncOP(stream,Convert.ToInt32(size));
op.CompletedAsync += delegate(object sender,EventArgs<IMAP_Client.ReadStringLiteralAsyncOP> e){
try{
// Read string literal failed.
if(op.Error != null){
callback(this,new EventArgs<Exception>(op.Error));
}
else{
// Append string-literal to fetch reader.
r.AppendString(TextUtils.QuoteString(Encoding.UTF8.GetString(stream.ToArray())));
// Read next fetch line completed synchronously.
if(!ReadNextFetchLine(imap,r,callback)){
ParseDataItems(imap,r,callback);
}
}
}
catch(Exception x){
callback(this,new EventArgs<Exception>(x));
}
finally{
op.Dispose();
}
};
// Read string literal completed sync.
if(!imap.ReadStringLiteralAsync(op)){
try{
// Read string literal failed.
if(op.Error != null){
callback(this,new EventArgs<Exception>(op.Error));
return true;
}
else{
// Append string-literal to fetch reader.
r.AppendString(TextUtils.QuoteString(Encoding.UTF8.GetString(stream.ToArray())));
return ReadNextFetchLine(imap,r,callback);
}
}
finally{
op.Dispose();
}
}
// Read string literal completed async.
else{
return true;
}
}
else{
throw new ParseException("No string-literal available '" + r.SourceString + "'.");
}
}