Skip to content

Instantly share code, notes, and snippets.

@hbulens
Last active January 13, 2018 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/347f82729dcf1fc62b5e050972abfba7 to your computer and use it in GitHub Desktop.
Save hbulens/347f82729dcf1fc62b5e050972abfba7 to your computer and use it in GitHub Desktop.
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