Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class SSOMRepositoryBase
{
#region Constructor
public SSOMRepositoryBase(string contextUrl)
{
// Set the Context Url
this.ContextUrl = contextUrl;
}
#endregion
#region Properties
internal string ContextUrl { get; set; }
#endregion
#region Methods
#region Read
internal List GetItems(string list, SPQuery query, Func<SPListItem, T> convertAction)
{
// Check if list name is not empty
if (string.IsNullOrEmpty(list))
{
return new List();
}
List resultSet = null;
using (SPSite site = new SPSite(this.ContextUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList spList = web.Lists.TryGetList(list);
SPListItemCollection listItems = query == null ? spList.Items : spList.GetItems(query);
if (listItems != null)
{
resultSet = listItems.Cast().Select(x => convertAction.Invoke(x)).ToList();
}
else
{
resultSet = new List();
}
}
}
return resultSet;
}
#endregion Read
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.