- Timestamp:
- 12/06/19 14:39:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs
r17371 r17374 1 1 using System; 2 using System.Collections; 2 3 using System.Collections.Generic; 3 4 using System.IO; … … 24 25 get => name; 25 26 set { 26 name = value; 27 Path = Name; 28 UpdatePath(); 27 if(Name != value) { 28 string oldName = Name; 29 name = value; 30 if (Path != null) { 31 var parts = Path.Split('.'); 32 for (int i = 0; i < parts.Length; ++i) 33 if (parts[i] == oldName) 34 parts[i] = Name; 35 36 Path = string.Join(".", parts); 37 } else 38 Path = Name; 39 40 UpdatePath(); 41 } 29 42 } 30 43 } … … 75 88 76 89 #region Public Methods 90 public void AddParameter(JsonItem item) { 91 if (Parameters == null) 92 Parameters = new List<JsonItem>(); 93 Parameters.Add(item); 94 item.Path = $"{Path}.{item.Name}"; 95 item.UpdatePath(); 96 } 97 77 98 public void UpdatePath() { 78 99 if (Parameters != null) … … 103 124 } 104 125 105 private bool IsInRange() => IsInRangeList() || 106 (Value.GetType().IsArray && ((object[])Value).All(x => IsInNumericRange(x))) || 107 (!Value.GetType().IsArray && IsInNumericRange(Value)); 108 109 private bool IsInRangeList() { 126 private bool IsInRange() { 127 bool b1 = true, b2 = true; 128 if (Value is IEnumerable && !(Value is string)) { 129 foreach (var x in (IEnumerable)Value) { 130 b1 = b1 ? IsInRangeList(x) : b1; 131 b2 = b2 ? IsInNumericRange(x) : b2; 132 } 133 } 134 else { 135 b1 = IsInRangeList(Value); 136 b2 = IsInNumericRange(Value); 137 } 138 139 return b1 || b2; 140 } 141 142 private bool IsInRangeList(object value) { 110 143 foreach (var x in Range) 111 if (x.Equals( Value)) return true;144 if (x.Equals(value)) return true; 112 145 return false; 113 146 } 114 147 115 148 private bool IsInNumericRange(object value) => 116 IsInNumericRange<long>(value) 149 IsInNumericRange<ulong>(value) 150 || IsInNumericRange<uint>(value) 151 || IsInNumericRange<ushort>(value) 152 || IsInNumericRange<long>(value) 117 153 || IsInNumericRange<int>(value) 118 154 || IsInNumericRange<short>(value) 119 155 || IsInNumericRange<byte>(value) 120 156 || IsInNumericRange<float>(value) 121 || IsInNumericRange<double>(value); 157 || IsInNumericRange<double>(value) 158 || (value is float && float.IsNaN((float)value)) 159 || (value is double && double.IsNaN((double)value)); 122 160 123 161 private bool IsInNumericRange<T>(object value) where T : IComparable { 124 162 object min = Range.First(), max = Range.Last(); 125 return value != null && min != null && max != null && value is T && min is T && max is T && 126 (((T)min).CompareTo(value) == -1 || ((T)min).CompareTo(value) == 0) && 127 (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0); 163 return 164 value != null && min != null && max != null && value is T && min is T && max is T && 165 (((T)min).CompareTo(value) == -1 || ((T)min).CompareTo(value) == 0) && 166 (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0); 128 167 } 129 168
Note: See TracChangeset
for help on using the changeset viewer.