/// <summary> /// Adds the given <see cref="Microsoft.SharePoint.SPContentType"/> object to the cache. /// </summary> /// <param name="contentType">Content type object.</param> /// <returns>>An <see cref="Microsoft.SharePoint.SPContentType"/> object in cache. Returned object is not necessary the same instance as the given one.</returns> /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="contentType"/> is null.</exception> public SPContentType AddContentType(SPContentType contentType) { CommonHelper.ConfirmNotNull(contentType, "contentType"); SPContentTypeLookupKey lookupKey = new SPContentTypeLookupKey(contentType); return(GetOrAdd(lookupKey, contentType)); }
/// <summary> /// Gets an <see cref="Microsoft.SharePoint.SPContentType"/> object representing list content type of the specified content type ID under the specified list. /// </summary> /// <param name="listUrl">Server-relative URL of the list.</param> /// <param name="contentTypeId">List content type ID.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPContentType"/> object in cache. NULL if list content type of given content type ID does not exist, or the specified list does not exist.</returns> /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="listUrl"/> is null.</exception> public SPContentType GetContentType(string listUrl, SPContentTypeId contentTypeId) { CommonHelper.ConfirmNotNull(listUrl, "listUrl"); SPListLookupKey listInfo = hashtable.EnsureKeyValue(listUrl, () => GetListInfoFromUrl(listUrl)); SPContentTypeLookupKey lookupKey = new SPContentTypeLookupKey(listInfo.ListId, contentTypeId); return(GetOrAdd(lookupKey, () => GetList(listInfo.WebId, listInfo.ListId).ContentTypes[contentTypeId])); }
/// <summary> /// Gets an <see cref="Microsoft.SharePoint.SPContentType"/> object representing site content type of the specified content type ID. /// </summary> /// <param name="contentTypeId">Content type ID.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPContentType"/> object in cache. NULL if site content type of given content type ID does not exist.</returns> public SPContentType GetContentType(SPContentTypeId contentTypeId) { SPContentTypeLookupKey lookupKey = new SPContentTypeLookupKey(Guid.Empty, contentTypeId); return(GetOrAdd(lookupKey, () => contextSite.RootWeb.ContentTypes[contentTypeId])); }