Instantly share code, notes, and snippets.
Last active
January 13, 2018 04:23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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