CSC510209. Inappropriate SPList collection usage.

Description

List name is culture specific string or could be changed later:
  • Avoid string based index calls to obtain the list.
  • Avoid using TryGetList method for the List access.

Potential performance issues:
  • Avoid all list enumerations via enumerator calls.
  • Avoid all list enumerations via linq Cast<T> expression.
  • Avoid all list enumerations via linq OfType<T> expression.

Bad code
code.png

Resolution

Consider retrieving list by its URL with SPWeb.GetList() method.

Sample

var listUrl = "/lists/tasks";
var taskList = web.GetList(SPUrlUtility.CombineUrl(web.Url, listUrl));

Links

SPWeb.GetList() method
SharePoint Custom Code Performance
Как писать правильный код для SharePoint

Last edited Jun 27, 2014 at 9:27 AM by dvd73, version 18

Comments

dvd73 Apr 29, 2014 at 9:13 PM 
Here is a discussion https://spcafcontrib.codeplex.com/discussions/543795