本文整理匯總了C#中System.IO.StringReader.Set方法的典型用法代碼示例。如果您正苦於以下問題:C# StringReader.Set方法的具體用法?C# StringReader.Set怎麽用?C# StringReader.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.Set方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadText
/// <summary>
/// Opens the specified file for reading.
/// </summary>
/// <param name="dataStorePath">The data store path specifying the file to open.</param>
/// <returns>An <see cref="ITextReader"/> representing the file opened.</returns>
public ITextReader ReadText( string dataStorePath )
{
try
{
if( dataStorePath.NullOrEmpty()
|| !DataStore.IsValidPath(dataStorePath) )
throw new ArgumentException("Invalid data store path!").StoreFileLine();
lock( this.syncLock )
{
var node = this.GetNodeAt(dataStorePath);
if( node.NullReference() )
throw new FileNotFoundException("File system entry not found!").StoreFileLine();
if( !(node is IDataStoreValue) )
throw new FileNotFoundException("File system entry is not a file!").StoreFileLine();
var textValue = node as IDataStoreTextValue;
if( textValue.NotNullReference() )
{
var reader = new StringReader();
reader.Set(textValue.Content);
return reader;
}
var binaryValue = node as IDataStoreBinaryValue;
if( binaryValue.NotNullReference() )
{
var ms = new MemoryStream(capacity: binaryValue.Content.Count);
ms.Write(binaryValue.Content.Array, binaryValue.Content.Offset, binaryValue.Content.Count);
ms.Position = 0;
return IOWrapper.ToTextReader(ms);
}
throw new Exception("Data store node value is neither text, nor binary based!").Store("nodeType", node.GetType());
}
}
catch( Exception ex )
{
ex.Store("dataStorePath", dataStorePath);
throw;
}
}