/// <summary> /// Gets an <see cref="Microsoft.SharePoint.SPField"/> object representing list column of the specified GUID, under the specified list. /// </summary> /// <param name="webId">Site GUID.</param> /// <param name="listId">List GUID.</param> /// <param name="fieldId">Field GUID.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPField"/> object in cache. NULL if list column of given GUID does not exist, or specified list does not exist.</returns> public SPField GetField(Guid webId, Guid listId, Guid fieldId) { SPFieldLookupKey lookupKey = new SPFieldLookupKey(listId, fieldId); SPField field = GetOrAdd(lookupKey, () => EnsureLocalXmlNode(GetList(webId, listId).Fields[fieldId])); return(field); }
/// <summary> /// Gets an <see cref="Microsoft.SharePoint.SPField"/> object representing list column of the specified GUID, under the specified list. /// </summary> /// <param name="webId">Site GUID.</param> /// <param name="listId">List GUID.</param> /// <param name="fieldId">Field GUID.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPField"/> object in cache. NULL if list column of given GUID does not exist, or specified list does not exist.</returns> public SPField GetField(Guid webId, Guid listId, Guid fieldId) { SPFieldLookupKey lookupKey = new SPFieldLookupKey(listId, fieldId); SPField field = GetOrAdd(lookupKey, () => EnsureLocalXmlNode(GetList(webId, listId).Fields[fieldId])); if (field != null && field.ParentList == null) { fieldInternalNames.EnsureKeyValue(field.InternalName, () => new SPFieldLookupKey(Guid.Empty, field.Id)); } return(field); }
/// <summary> /// Gets an <see cref="Microsoft.SharePoint.SPField"/> object representing site column of the specified GUID. /// </summary> /// <param name="fieldId">Field GUID.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPField"/> object in cache. NULL if site column of given GUID does not exist.</returns> public SPField GetField(Guid fieldId) { SPFieldLookupKey lookupKey = new SPFieldLookupKey(Guid.Empty, fieldId); SPField field = GetOrAdd(lookupKey, () => EnsureLocalXmlNode(contextSite.RootWeb.Fields[fieldId])); if (field != null) { hashtable.EnsureKeyValue(field.InternalName, () => new SPFieldLookupKey(Guid.Empty, field.Id)); } return(field); }
/// <summary> /// Adds the given <see cref="Microsoft.SharePoint.SPField"/> object to the cache. /// </summary> /// <param name="field">Field object.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPField"/> 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="field"/> is null.</exception> public SPField AddField(SPField field) { CommonHelper.ConfirmNotNull(field, "field"); SPFieldLookupKey lookupKey = new SPFieldLookupKey(field); if (field.ParentList == null) { fieldInternalNames.EnsureKeyValue(field.InternalName, () => new SPFieldLookupKey(Guid.Empty, field.Id)); } EnsureLocalXmlNode(field); return(GetOrAdd(lookupKey, field)); }
/// <summary> /// Get an <see cref="Microsoft.SharePoint.SPField"/> object representing site column of the specified internal name. /// </summary> /// <param name="internalName">Internal name.</param> /// <returns>An <see cref="Microsoft.SharePoint.SPField"/> object in cache. NULL if site column of given internal name does not exist.</returns> /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="internalName"/> is null.</exception> public SPField TryGetField(string internalName) { CommonHelper.ConfirmNotNull(internalName, "internalName"); SPFieldLookupKey lookupKey = hashtable[internalName] as SPFieldLookupKey; if (lookupKey != null) { return(GetField(lookupKey.FieldId)); } try { SPField field = contextSite.RootWeb.Fields.GetFieldByInternalName(internalName); return(AddField(field)); } catch (ArgumentException) { } return(null); }