c# 4 または 4.5 で匿名型と動的型を作成できることは知っていますが、それがどのように機能するかはわかりません。SharePoint サイト コレクションを反復処理しており、サブサイトごとに項目を 3 列でリストに追加したいと考えています。
ただし、このメソッドに固有のものであるため、このためのクラスを作成したくありません。
private void RenderGrid()
{
string currentUrl = SPContext.Current.Site.Url;
List<object> listobject= new List<object>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite clientSiteCollection = new SPSite(currentUrl))
{
foreach (SPWeb web in clientSiteCollection.AllWebs)
{
string webtemplate = web.Properties["WebTemplate"];
if (webtemplate.Equals("xx"))
{
SPList xx = web.Lists.TryGetList(Constants.Lists.xx);
if (opportunityInfoList != null)
{
opportunityInfo.Add(new object() {
col1 = "value1",
col2 = "value2",
col3 = "value3"
});
}
}
}
}
});
lastCreatedOpportunitiesGrid.DataSource = opportunityInfo;
lastCreatedOpportunitiesGrid.DataBind();
}