Summer.Batch.Core.Converter.DefaultJobParametersConverter.GetProperties C# (CSharp) Method

GetProperties() public method

Use the same suffixes to create properties (omitting the string suffix because it is the default). Non-identifying parameters will be prefixed with the NonIdentifyingFlag. However, since parameters are identifying by default, they will not be prefixed with the IdentifyingFlag.
public GetProperties ( JobParameters parms ) : NameValueCollection
parms JobParameters
return System.Collections.Specialized.NameValueCollection
        public NameValueCollection GetProperties(JobParameters parms)
        {
            if (parms == null || parms.IsEmpty())
            {
                return new NameValueCollection();
            }

            IDictionary<string, JobParameter> parameters = parms.GetParameters();
            NameValueCollection result = new NameValueCollection();

            foreach (KeyValuePair<string, JobParameter> entry in parameters)
            {
                string key = entry.Key;
                JobParameter jobParameter = entry.Value;
                Object value = jobParameter.Value;
                if (value != null)
                {
                    key = (!jobParameter.Identifying ? NonIdentifyingFlag : "") + key;
                    if (jobParameter.Type == JobParameter.ParameterType.Date)
                    {
                        result.Set(key + DateType, string.Format(_dateFormat, value));
                    }
                    else if (jobParameter.Type == JobParameter.ParameterType.Long)
                    {
                        result.Set(key + LongType, string.Format(_numberFormat, value));
                    }
                    else if (jobParameter.Type == JobParameter.ParameterType.Double)
                    {
                        result.Set(key + DoubleType, string.Format(_decimalFormat, (double)value));
                    }
                    else
                    {
                        result.Set(key, "" + value);
                    }
                }
            }

            return result;
        }
    }

Usage Example

        public void GetPropertiesTest()
        {
            //OrderedDictionary<string, JobParameter> myJobP = new OrderedDictionary<string, JobParameter>
            IDictionary<string, JobParameter> myJobP = new Dictionary<string, JobParameter>
            {
                {"p1", new JobParameter("param1")},
                {"p2", new JobParameter(2)},
                {"p3", new JobParameter(3.0)},
                {"p4", new JobParameter(DateTime.Parse("1970-07-31"))}
            };

            JobParameters jp = new JobParameters(myJobP);
            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props = converter.GetProperties(jp);
            Assert.IsNotNull(props);
            Assert.AreEqual(4,props.Count);
            foreach (string key in props.Keys)
            {
                string value = props[key];
                Assert.IsNotNull(value);
                if (key.Contains("p1"))
                {
                    Assert.AreEqual("p1", key);
                }
                if (key.Contains("p2"))
                {
                    Assert.AreEqual("p2(long)", key);
                }
                if (key.Contains("p3"))
                {
                    Assert.AreEqual("p3(double)", key);
                }
                if (key.Contains("p4"))
                {
                    Assert.AreEqual("p4(date)", key);
                }
            }
        }