|
10 | 10 | using System.Linq;
|
11 | 11 | using System.Management.Automation;
|
12 | 12 | using System.Reflection;
|
| 13 | +using Microsoft.PowerShell.EditorServices.Utility; |
13 | 14 |
|
14 | 15 | namespace Microsoft.PowerShell.EditorServices
|
15 | 16 | {
|
@@ -159,44 +160,49 @@ private static string GetValueString(object value, bool isExpandable)
|
159 | 160 | entry.Key,
|
160 | 161 | GetValueString(entry.Value, GetIsExpandable(entry.Value)));
|
161 | 162 | }
|
162 |
| - else if (value.ToString().Equals(objType.ToString())) |
| 163 | + else |
163 | 164 | {
|
164 |
| - // If the ToString() matches the type name, then display the type |
165 |
| - // name in PowerShell format. |
166 |
| - string shortTypeName = objType.Name; |
| 165 | + string valueToString = value.SafeToString(); |
167 | 166 |
|
168 |
| - // For arrays and ICollection, display the number of contained items. |
169 |
| - if (value is Array) |
| 167 | + if (valueToString.Equals(objType.ToString())) |
170 | 168 | {
|
171 |
| - var arr = value as Array; |
172 |
| - if (arr.Rank == 1) |
| 169 | + // If the ToString() matches the type name, then display the type |
| 170 | + // name in PowerShell format. |
| 171 | + string shortTypeName = objType.Name; |
| 172 | + |
| 173 | + // For arrays and ICollection, display the number of contained items. |
| 174 | + if (value is Array) |
173 | 175 | {
|
174 |
| - shortTypeName = InsertDimensionSize(shortTypeName, arr.Length); |
| 176 | + var arr = value as Array; |
| 177 | + if (arr.Rank == 1) |
| 178 | + { |
| 179 | + shortTypeName = InsertDimensionSize(shortTypeName, arr.Length); |
| 180 | + } |
175 | 181 | }
|
| 182 | + else if (value is ICollection) |
| 183 | + { |
| 184 | + var collection = (ICollection)value; |
| 185 | + shortTypeName = InsertDimensionSize(shortTypeName, collection.Count); |
| 186 | + } |
| 187 | + |
| 188 | + valueString = "[" + shortTypeName + "]"; |
176 | 189 | }
|
177 |
| - else if (value is ICollection) |
| 190 | + else |
178 | 191 | {
|
179 |
| - var collection = (ICollection)value; |
180 |
| - shortTypeName = InsertDimensionSize(shortTypeName, collection.Count); |
| 192 | + valueString = valueToString; |
181 | 193 | }
|
182 |
| - |
183 |
| - valueString = "[" + shortTypeName + "]"; |
184 |
| - } |
185 |
| - else |
186 |
| - { |
187 |
| - valueString = value.ToString(); |
188 | 194 | }
|
189 | 195 | }
|
190 | 196 | else
|
191 | 197 | {
|
192 |
| - // ToString() output is not the typename, so display that as this object's value |
| 198 | + // Value is a scalar (not expandable). If it's a string, display it directly otherwise use SafeToString() |
193 | 199 | if (value is string)
|
194 | 200 | {
|
195 | 201 | valueString = "\"" + value + "\"";
|
196 | 202 | }
|
197 | 203 | else
|
198 | 204 | {
|
199 |
| - valueString = value.ToString(); |
| 205 | + valueString = value.SafeToString(); |
200 | 206 | }
|
201 | 207 | }
|
202 | 208 |
|
|
0 commit comments