Skip to content

Commit 4dd42c3

Browse files
author
Hovsep Mkrtchyan
committed
Changed ToString method to call Culture agnostic to string method if possible.
1 parent 1d81425 commit 4dd42c3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/CLU/Microsoft.CLU/System.Management.Automation/ValidateSetAttribute.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Linq;
34
using System.Reflection;
45

@@ -32,7 +33,29 @@ protected override void ValidateElement(object element)
3233
else if (element.GetType().GetTypeInfo().IsEnum ||
3334
element.GetType().GetTypeInfo().IsValueType)
3435
{
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+
}
3659
}
3760

3861
if (strVal != null)

0 commit comments

Comments
 (0)