Return a List based on very similar data I am rewriting an old VB.NET app in C#. I will not subject you to the old VB.NET code that I am writing (the original method that I have already refactored was over 700 lines long).

The following is what we call On Demand Reports. There is a stored procedure that these objects fill in for us. I don't have a 100% understanding of why most of what I am doing is just static string text but it is.

What I want to do is to find a better way to represent the List&lt;MyObject&gt; (see the embedded comments).

 private IEnumerable&lt;MyObject&gt; GetOnDemandInputsBy(int key)
        {
            var inputs = new List&lt;MyObject&gt;();
            //This is actually called 13 times with different parameter variables (the parameter called parameter) and a different static dictionary 
            inputs.Add(AssembleMyObject(key, "@BeginTime", MyObjectPropertyConstants.BeginTime()));
            inputs.Add(AssembleMyObject(key, "@EndTime", MyObjectPropertyConstants.EndTime()));

            return inputs;
        }

        //This method is fine with me. It is just here for context
        private static IEnumerable&lt;MyObjectProperty&gt; AssembleMyObjectProperty(Dictionary&lt;string, string&gt; dictionary)
        {

            return dictionary.Select(item =&gt; new MyObjectProperty {PropertyName = item.Key, PropertyValue = item.Value});
        }

        //I feel like I am passing to many things into this method and its doing to much
        private MyObject AssembleMyObject(int key, string parameter, Dictionary&lt;string, string&gt; dictionary)
        {
            //this is set to 0 in the constructor, I am not sure why the original developers chose 10 for every new object
            _displayOrder += 10;
            var MyObject = new MyObject
            {
                DisplayOrder = _displayOrder,
                ParameterName = parameter,
                QueryKey = key,
            };
            MyObject.MyObjectProperties.AddRange(AssembleMyObjectProperty(dictionary));
            return MyObject;
        }

    //This seems like a bad idea as well but all the data is static and I created a separate dictionary for each of the parameter types     
    public class MyObjectPropertyConstants
    {
        public static Dictionary&lt;string, string&gt; BeginTime()
        {
            return new Dictionary&lt;string, string&gt;
            {
                {"stuff", "@BeginTime"},
                {"VISIBLE", "TRUE"},
                {"CAPTION", "*beginTime"},
                {"DISPLAYTYPE", "DATEPICKER"},
                {"DATATYPE", "DATE"},
            };
        }

        public static Dictionary&lt;string, string&gt; EndTime()
        {
            return new Dictionary&lt;string, string&gt;
            {
                {"Name", "@EndTime"},
                {"VISIBLE", "TRUE"},
                {"CAPTION", "*EndTime"},
                {"DISPLAYTYPE", "DATEPICKER"},
                {"DATATYPE", "DATE"},
            };
        }
   }


As previously states this is the refactored version so far. The original code to do the above chunk is 180 lines. The method that I am rewriting is over 700 lines long.

Any Suggestions?
var inputs = new List&lt;MyObject&gt;();
inputs.Add(AssembleMyObject(key, "@BeginTime", MyObjectPropertyConstants.BeginTime()));
inputs.Add(AssembleMyObject(key, "@EndTime", MyObjectPropertyConstants.EndTime()));

return inputs;


You could rewrite this to make it more DRY using LINQ into:

return new Func&lt;Dictionary&lt;string, string&gt;&gt;[]
{
    MyObjectPropertyConstants.BeginTime,
    MyObjectPropertyConstants.EndTime
}.Select(f =&gt; AssembleMyObject(key, "@" + f.Name, f()).ToList();




var MyObject


Local variables are usually named in camelCase, e.g. myObject.



public static Dictionary&lt;string, string&gt; BeginTime()


Method should be named using verbs, this looks more like a property. Thought making this into a property would make the above LINQ rewrite more difficult.



new Dictionary&lt;string, string&gt;
{
    {"stuff", "@BeginTime"},
    {"VISIBLE", "TRUE"},
    {"CAPTION", "*beginTime"},
    {"DISPLAYTYPE", "DATEPICKER"},
    {"DATATYPE", "DATE"},
};


Does order matter here? If it does, you shouldn't use Dictionary, since it doesn't guarantee ordering.