本文整理汇总了C#中ListItem.AddKeyword方法的典型用法代码示例。如果您正苦于以下问题:C# ListItem.AddKeyword方法的具体用法?C# ListItem.AddKeyword怎么用?C# ListItem.AddKeyword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListItem
的用法示例。
在下文中一共展示了ListItem.AddKeyword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadCSV
/// <summary>
/// Load a CSV file, read all entries and return ListItem objects
/// </summary>
/// <param name="filename">CSV file</param>
/// <returns>Enumarator of ListItem objects</returns>
public static IEnumerable<ListItem> LoadCSV(string filename)
{
char valuedelimiter = ',';
char keywordDelimiter = ';';
string[] lineParts;
List<ListItem> listItems = new List<ListItem>();
List<string> headers = new List<string>() ;
int lineCounter = 0;
try
{
using (var textReader = new System.IO.StreamReader(filename))
{
while (!textReader.EndOfStream)
{
lineCounter++;
lineParts = textReader.ReadLine().Split(valuedelimiter);
// The first line should be a header, read that to know the index of the columns
if (lineCounter==1)
{
for (int h = 0; h < lineParts.Length; h++)
headers.Add(lineParts[h]);
continue;
}
// Do some validation on this line
if (lineParts.Length != headers.Count())
throw new FormatException("Number of values doesn't match number of headers.");
ListItem newListItem = new ListItem();
// Get the all the values, whatever they are
for (int i=0;i<lineParts.Length;i++)
{
// Keywords need special handling
if (headers[i]=="keywords")
{
string[] keywords = lineParts[i].Split(keywordDelimiter);
foreach (string keyword in keywords)
newListItem.AddKeyword(keyword);
}
else if (isString(lineParts[i]))
newListItem[headers[i]] = lineParts[i];
else
newListItem[headers[i]] = int.Parse(lineParts[i]);
}
listItems.Add(newListItem);
}
return listItems;
}
}
catch (FormatException ex)
{
throw new FormatException("Error parsing CSV file " + filename + " at line " + lineCounter, ex);
}
}