File tree Expand file tree Collapse file tree 2 files changed +300
-129
lines changed Expand file tree Collapse file tree 2 files changed +300
-129
lines changed Original file line number Diff line number Diff line change @@ -137,15 +137,32 @@ private AddToHistoryOption GetAddToHistoryOption(string line)
137
137
}
138
138
139
139
object value = Options . AddToHistoryHandler ( line ) ;
140
+ if ( value is PSObject psObj )
141
+ {
142
+ value = psObj . BaseObject ;
143
+ }
144
+
145
+ if ( value is bool boolValue )
146
+ {
147
+ return boolValue ? AddToHistoryOption . MemoryAndFile : AddToHistoryOption . SkipAdding ;
148
+ }
140
149
141
- if ( LanguagePrimitives . TryConvertTo ( value , out AddToHistoryOption enumValue ) )
150
+ if ( value is AddToHistoryOption enumValue )
142
151
{
143
152
return enumValue ;
144
153
}
145
154
146
- if ( value is bool boolValue && ! boolValue )
155
+ if ( value is string strValue && Enum . TryParse ( strValue , out enumValue ) )
147
156
{
148
- return AddToHistoryOption . SkipAdding ;
157
+ return enumValue ;
158
+ }
159
+
160
+ // 'TryConvertTo' incurs exception handling when the value cannot be converted to the target type.
161
+ // It's expensive, especially when we need to process lots of history items from file during the
162
+ // initialization. So do the conversion as the last resort.
163
+ if ( LanguagePrimitives . TryConvertTo ( value , out enumValue ) )
164
+ {
165
+ return enumValue ;
149
166
}
150
167
}
151
168
You can’t perform that action at this time.
0 commit comments