本文整理汇总了C#中IEntityCollection.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityCollection.OfType方法的具体用法?C# IEntityCollection.OfType怎么用?C# IEntityCollection.OfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntityCollection
的用法示例。
在下文中一共展示了IEntityCollection.OfType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportEntityCollection
// Exports an IEntityCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False)
public static dynamic ExportEntityCollection(IEntityCollection collection, bool UseActiveDocument)
{
dynamic doc = null;
WordHelper wordProxy = new WordHelper();
bool bUseActiveDocument = false;
dynamic rg = null;
// if Word is active then use it
if (wordProxy.GetWord())
{
// obtain a reference to the selection range
if (UseActiveDocument)
{
rg = wordProxy.Word.Selection.Range;
bUseActiveDocument = true;
}
else
{
wordProxy.CreateDocument();
}
}
else
{
wordProxy.CreateWord();
wordProxy.CreateDocument();
}
List<string> columnNames = new List<string>();
// get column properties
IEnumerable<IEntityProperty> columnProperties = collection.OfType<IEntityObject>().First().Details.Properties.All();
int columnCounter = 1;
int rowCounter = 1;
// add table
dynamic oTable = null;
if (bUseActiveDocument)
{
oTable = wordProxy.AddTable(1, columnProperties.Count(), rg);
}
else
{
oTable = wordProxy.AddTable(1, columnProperties.Count());
}
// add columns names to the list
foreach (IEntityProperty entityProperty in columnProperties)
{
columnNames.Add(entityProperty.Name);
// add column headers to table
wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName);
columnCounter += 1;
}
// add values on the row following the headers
rowCounter = 2;
// iterate the collection and extract values by column name
foreach (IEntityObject entityObj in collection)
{
oTable.Rows.Add();
for (int i = 0; i <= columnNames.Count - 1; i++)
{
wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i]));
}
rowCounter += 1;
}
doc = wordProxy.Document;
wordProxy.ShowDocument();
return doc;
}
示例2: HtmlExportEntityCollection
// Create HTML table based on IEntityCollection
public static string HtmlExportEntityCollection(IEntityCollection collection)
{
List<string> columnNames = new List<string>();
bool bFirstItem = true;
string sBody = "";
// get column properties
IEnumerable<IEntityProperty> columnProperties = collection.OfType<IEntityObject>().First().Details.Properties.All();
// iterate the collection and extract values by column name
foreach (IEntityObject entityObj in collection)
{
if (bFirstItem)
{
// opening an html tag and creating a table
//sBody = "<html>"
//sBody = sBody + "</br></br>"
//sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >"
sBody = "<table border=\"1\">";
// add columns names to the list
// row begins
sBody = sBody + "<tr>";
foreach (IEntityProperty entityProperty in columnProperties)
{
columnNames.Add(entityProperty.Name);
sBody = sBody + "<td>";
sBody = sBody + " " + entityProperty.DisplayName;
sBody = sBody + "</td>";
}
// row ends
sBody = sBody + "</tr>";
bFirstItem = false;
}
sBody = sBody + "<tr>";
for (int i = 0; i <= columnNames.Count - 1; i++)
{
sBody = sBody + "<td>";
sBody = sBody + LightSwitchHelper.GetValue(entityObj, columnNames[i]);
sBody = sBody + "</td>";
}
sBody = sBody + "</tr>";
}
// Add closing tags if there was at least one item
// bFirstItem = True by default
// It is set to False when the first item is encountered
if (!bFirstItem)
{
// closing the tags
sBody = sBody + "</table>";
//sBody = sBody + "</body>"
//sBody = sBody + "</html>"
}
return sBody;
}