本文整理汇总了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;
}
}