- Timestamp:
- 03/24/15 15:59:05 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer/3.3/CreateExperimentDialog.cs
r12012 r12254 169 169 else boolParameters.Remove(parameter); 170 170 } 171 172 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 173 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 174 if (isEnumValue) { 175 if (e.Item.Checked) multipleChoiceParameters.Add(parameter, new HashSet<IItem>(new EnumValueEqualityComparer())); 176 else multipleChoiceParameters.Remove(parameter); 177 } 171 178 } 172 179 … … 192 199 isOptionalConstrainedValueParameter 193 200 || typeof(ConstrainedValueParameter<>).Equals(parameter.GetType().GetGenericTypeDefinition()); 194 195 if (isConstrainedValueParameter) { 201 bool isEnumValue = parameter.Value != null && parameter.Value.GetType().IsGenericType 202 && typeof(EnumValue<>).IsAssignableFrom(parameter.Value.GetType().GetGenericTypeDefinition()); 203 204 if (isConstrainedValueParameter || isEnumValue) { 196 205 detailsTypeLabel.Text = "Choices:"; 197 206 choicesListView.Tag = parameter; 198 207 199 if (isOptionalConstrainedValueParameter) { 200 choicesListView.Items.Add(new ListViewItem("-") { 201 Tag = optionalNullChoice, 202 Checked = multipleChoiceParameters.ContainsKey(parameter) 203 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 204 }); 205 } 206 dynamic constrainedValuedParameter = parameter; 207 dynamic validValues = constrainedValuedParameter.ValidValues; 208 foreach (var choice in validValues) { 209 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 210 Tag = choice, 211 Checked = multipleChoiceParameters.ContainsKey(parameter) 212 && multipleChoiceParameters[parameter].Contains(choice) 213 }); 208 if (isConstrainedValueParameter) { 209 if (isOptionalConstrainedValueParameter) { 210 choicesListView.Items.Add(new ListViewItem("-") { 211 Tag = optionalNullChoice, 212 Checked = multipleChoiceParameters.ContainsKey(parameter) 213 && multipleChoiceParameters[parameter].Contains(optionalNullChoice) 214 }); 215 } 216 dynamic constrainedValuedParameter = parameter; 217 dynamic validValues = constrainedValuedParameter.ValidValues; 218 foreach (var choice in validValues) { 219 choicesListView.Items.Add(new ListViewItem(choice.ToString()) { 220 Tag = choice, 221 Checked = multipleChoiceParameters.ContainsKey(parameter) 222 && multipleChoiceParameters[parameter].Contains(choice) 223 }); 224 } 225 } 226 if (isEnumValue) { 227 var enumType = parameter.Value.GetType().GetGenericArguments()[0]; 228 var enumValueType = typeof(EnumValue<>).MakeGenericType(enumType); 229 foreach (var enumChoice in Enum.GetValues(enumType)) { 230 choicesListView.Items.Add(new ListViewItem(enumChoice.ToString()) { 231 Tag = Activator.CreateInstance(enumValueType, enumChoice), 232 Checked = multipleChoiceParameters.ContainsKey(parameter) 233 && multipleChoiceParameters[parameter].Any((dynamic item) => item.Value.Equals(enumChoice)) 234 }); 235 } 214 236 } 215 237 choicesListView.Enabled = multipleChoiceParameters.ContainsKey(parameter); … … 455 477 if (valueParam != null && (valueParam.Value is ValueTypeValue<bool> 456 478 || valueParam.Value is ValueTypeValue<int> 457 || valueParam.Value is ValueTypeValue<double>) 479 || valueParam.Value is ValueTypeValue<double> 480 || (valueParam.Value != null && valueParam.Value.GetType().IsGenericType 481 && typeof(EnumValue<>).IsAssignableFrom(valueParam.Value.GetType().GetGenericTypeDefinition()))) 458 482 || typeof(OptionalConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition()) 459 483 || typeof(ConstrainedValueParameter<>).IsAssignableFrom(param.GetType().GetGenericTypeDefinition())) … … 650 674 } 651 675 #endregion 676 677 #region EnumValueEqualityComparer 678 private class EnumValueEqualityComparer : EqualityComparer<IItem> { 679 public override bool Equals(IItem x, IItem y) { 680 if (typeof(EnumValue<>).IsAssignableFrom(x.GetType().GetGenericTypeDefinition()) && 681 typeof(EnumValue<>).IsAssignableFrom(y.GetType().GetGenericTypeDefinition())) { 682 dynamic enumValueX = x; 683 dynamic enumValueY = y; 684 return enumValueX.Value.Equals(enumValueY.Value); 685 } else return object.ReferenceEquals(x, y); 686 } 687 688 public override int GetHashCode(IItem obj) { 689 if (typeof(EnumValue<>).IsAssignableFrom(obj.GetType().GetGenericTypeDefinition())) { 690 dynamic enumValue = obj; 691 return enumValue.Value.GetHashCode(); 692 } else return obj.GetHashCode(); 693 } 694 } 695 #endregion 696 652 697 #endregion 653 698
Note: See TracChangeset
for help on using the changeset viewer.