I have a function that loads a large selectlist for ASP.NET MVC. This functions has a methodsize of 354 rows. I want to refactor to more functions or to a local field so that each function will be less than 40 lines.
Here is the code snippet:
public static SelectList CreateShutterSpeedList()
{
var shutterSpeedList = new List<CameraSettingItem>();
var secNotationPostfix = "\"";
shutterSpeedList.Add(new CameraSettingItem
{
Id = ShutterSpeedDefaultValue,
Description = string.Empty
});
shutterSpeedList.Add(new CameraSettingItem
{
Id = 1,
Description = "30" + secNotationPostfix
});
etc
Maybe a private list as a variable ? Or loading from file ? Or else...?
If IDs above
ShutterSpeedDefaultValue
are assigned sequentially, you could create an array of descriptions first, and then convert it toCameraSettingItem
list with LINQ:You could also create a list of
CameraSettingItem
s outside of your method's body, like this: