本文整理汇总了C#中IFactory.create方法的典型用法代码示例。如果您正苦于以下问题:C# IFactory.create方法的具体用法?C# IFactory.create怎么用?C# IFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFactory
的用法示例。
在下文中一共展示了IFactory.create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromStream
/// <summary>
/// Reads the file from the stream
/// </summary>
/// <param name="path">Path being used to load the file</param>
/// <param name="extent">Extet being stored</param>
/// <param name="settings">Settings being used to store it.</param>
private void ReadFromStream(IExtent extent, IFactory factory, Stream stream, CSVSettings settings)
{
if (settings == null)
{
settings = new CSVSettings();
}
var columns = settings.Columns;
var createColumns = false;
using (var streamReader = new StreamReader(stream, Encoding.GetEncoding(settings.Encoding)))
{
if (columns == null)
{
createColumns = true;
}
// Reads header, if necessary
if (settings.HasHeader)
{
columns.Clear();
// Creates the column names for the headline
var ignoredLine = streamReader.ReadLine();
var columnNames = SplitLine(ignoredLine, settings);
foreach (var columnName in columnNames)
{
columns.Add(columnName);
}
}
// Reads the data itself
string line;
while ((line = streamReader.ReadLine()) != null)
{
var values = SplitLine(line, settings);
var csvObject = factory.create(null);
// we now have the created object, let's fill it
var valueCount = values.Count;
for (var n = 0; n < valueCount; n++)
{
string foundColumn;
// Check, if we have enough columns, if we don't have enough columns, create one
if (columns.Count <= n && (createColumns || !settings.HasHeader))
{
// Create new column
foundColumn = $"Column {n + 1}";
columns.Add(foundColumn);
}
else
{
foundColumn = columns[n];
}
csvObject.set(foundColumn, values[n]);
}
extent.elements().add(csvObject);
}
}
}