当前位置: 首页>>代码示例>>C#>>正文


C# IEntityCollection.OfType方法代码示例

本文整理汇总了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;
        }
开发者ID:sjnaughton,项目名称:OfficeSharp,代码行数:75,代码来源:Word.cs

示例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;
        }
开发者ID:sjnaughton,项目名称:OfficeSharp,代码行数:58,代码来源:Outlook.cs


注:本文中的IEntityCollection.OfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。