我有一个对象:
public class SiteInfo
{
public string Title { get; set; }
public string URL { get; set; }
public string Type { get; set; }
}
我用来创建一个列表: var sites = new List();
foreach (SPWeb site in web.GetSubwebsForCurrentUser())
{
string sitetype = getConfigurationKey(site, "siteType");
//If sites have a site type then add to list
if (sitetype != "*ERROR*" && sitetype != "*KEYNOTFOUND*")
{
SiteInfo s = new SiteInfo();
s.Title = site.Title;
s.URL = site.Url;
s.Type = sitetype;
sites.Add(s);
}
}
//sort list by type
sites.Sort((x, y) => string.Compare(x.Type, y.Type));
// serialize and send..
JavaScriptSerializer serializer = new JavaScriptSerializer();
StringBuilder sbJsonResults = new StringBuilder();
serializer.Serialize(sites, sbJsonResults);
etc.....
但是,我想做的是在序列化站点之前按类型对站点进行分组。这是否可以使用 LINQ 或其他方法。