private List <MotionSensorSettingsTest> CreateMotionSensorSettingsTests(MotionSensorSettingsTest template, string propertyName, int min, int max, int inc) { List <MotionSensorSettingsTest> result = new List <MotionSensorSettingsTest>(); for (int i = min; i <= max; i += inc) { MotionSensorSettingsTest test = new MotionSensorSettingsTest(template); test.UpdateProperty(propertyName, i); result.Add(test); } return(result); }
/// <summary> /// Copies the properties of the template class parameter, allowing the values to be cloned /// </summary> /// <param name="template"></param> public MotionSensorSettingsTest(MotionSensorSettingsTest template) { foreach (PropertyInfo property in typeof(MotionSensorSettingsTest).GetProperties()) { //set the value, if the property exposes a setter var value = property.GetValue(template); if (property.GetSetMethod(true) != null) { property.SetValue(this, value); } } HashCode = Helpers.ShortDateStamp() + this.GetHashCode(); //unique per object }
}//PopulateSequentialChange private void Convert(DataTable dt) { //get a template object of the MotionSensorSettingsTest, and load the defaults, //otherwide database is queried on every object created to load defaults MotionSensorSettingsTest template = new MotionSensorSettingsTest(); template.LoadDefaults(); foreach (DataRow dr in dt.Rows) { MotionSetting singleSetting = new MotionSetting(); singleSetting.propertyName = dr["settingTypeName"].ToString(); singleSetting.list = new List <MotionSensorSettingsTest>(); System.Type propertyType = ReturnPropertyType(singleSetting.propertyName); if (propertyType.Name == "Int16" || propertyType.Name == "Int32") { int min = dr["minimum"].ToString().StringToInt(); int max = dr["maximum"].ToString().StringToInt(); int inc = dr["increment"].ToString().StringToInt(); singleSetting.list.AddRange(CreateMotionSensorSettingsTests(template, singleSetting.propertyName, min, max, inc)); } else if (propertyType.Name == "Decimal") { decimal min = dr["minimum"].ToString().StringToDec(); decimal max = dr["maximum"].ToString().StringToDec(); decimal inc = dr["increment"].ToString().StringToDec(); singleSetting.list.AddRange(CreateMotionSensorSettingsTests(template, singleSetting.propertyName, min, max, inc)); } else if (propertyType.Name != "boolean") { throw new Exception("Unsupported property type. Int's, decimal or booleans only"); } seperateSettingLists.Add(singleSetting); } //each datarow } //Convert