File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
src/CLU/Microsoft.CLU/System.Management.Automation Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
+ using System . Globalization ;
2
3
using System . Linq ;
3
4
using System . Reflection ;
4
5
@@ -32,7 +33,29 @@ protected override void ValidateElement(object element)
32
33
else if ( element . GetType ( ) . GetTypeInfo ( ) . IsEnum ||
33
34
element . GetType ( ) . GetTypeInfo ( ) . IsValueType )
34
35
{
35
- strVal = element . ToString ( ) ;
36
+ var cultureIndependentStringify = element . GetType ( )
37
+ . GetTypeInfo ( )
38
+ . GetDeclaredMethods ( "ToString" )
39
+ . Where ( m =>
40
+ {
41
+ var parameters = m . GetParameters ( ) ;
42
+ if ( parameters != null &&
43
+ parameters . Count ( ) == 1 &&
44
+ parameters . First ( ) . ParameterType == typeof ( IFormatProvider ) )
45
+ {
46
+ return true ;
47
+ }
48
+ return false ;
49
+ } ) . FirstOrDefault ( ) ;
50
+
51
+ if ( cultureIndependentStringify != null )
52
+ {
53
+ strVal = ( string ) cultureIndependentStringify . Invoke ( element , new [ ] { CultureInfo . InvariantCulture } ) ;
54
+ }
55
+ else
56
+ {
57
+ strVal = element . ToString ( ) ;
58
+ }
36
59
}
37
60
38
61
if ( strVal != null )
You can’t perform that action at this time.
0 commit comments