Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d9bc2bb3
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d9bc2bb3
编写于
1月 25, 2016
作者:
A
Artur Spychaj
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7951 from drognanar/issue7133
Add culture dependant object formatting in REPL
上级
1f8e3b67
50ee0c82
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
213 addition
and
70 deletion
+213
-70
src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs
src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs
+27
-22
src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs
...rs/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs
+12
-0
src/Compilers/VisualBasic/Portable/SymbolDisplay/ObjectDisplay.vb
...ilers/VisualBasic/Portable/SymbolDisplay/ObjectDisplay.vb
+26
-22
src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/ObjectDisplayTests.vb
...sualBasic/Test/Symbol/SymbolDisplay/ObjectDisplayTests.vb
+8
-1
src/Scripting/CSharp/Hosting/ObjectFormatter/CSharpObjectFormatter.cs
...g/CSharp/Hosting/ObjectFormatter/CSharpObjectFormatter.cs
+12
-11
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
+59
-0
src/Scripting/Core/Hosting/ObjectFormatter/ObjectFormatter.cs
...Scripting/Core/Hosting/ObjectFormatter/ObjectFormatter.cs
+7
-2
src/Scripting/VisualBasic/Hosting/ObjectFormatter/VisualBasicObjectFormatter.vb
...sic/Hosting/ObjectFormatter/VisualBasicObjectFormatter.vb
+11
-12
src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb
src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb
+51
-0
未找到文件。
src/Compilers/CSharp/Portable/SymbolDisplay/ObjectDisplay.cs
浏览文件 @
d9bc2bb3
...
...
@@ -335,7 +335,7 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
return
pooledBuilder
.
ToStringAndFree
();
}
internal
static
string
FormatLiteral
(
sbyte
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
sbyte
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
))
{
...
...
@@ -345,11 +345,11 @@ internal static string FormatLiteral(sbyte value, ObjectDisplayOptions options)
}
else
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
}
}
internal
static
string
FormatLiteral
(
byte
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
byte
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
))
{
...
...
@@ -357,11 +357,11 @@ internal static string FormatLiteral(byte value, ObjectDisplayOptions options)
}
else
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
}
}
internal
static
string
FormatLiteral
(
short
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
short
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
))
{
...
...
@@ -371,11 +371,11 @@ internal static string FormatLiteral(short value, ObjectDisplayOptions options)
}
else
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
}
}
internal
static
string
FormatLiteral
(
ushort
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
ushort
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
))
{
...
...
@@ -383,11 +383,11 @@ internal static string FormatLiteral(ushort value, ObjectDisplayOptions options)
}
else
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
}
}
internal
static
string
FormatLiteral
(
int
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
int
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
))
{
...
...
@@ -395,11 +395,11 @@ internal static string FormatLiteral(int value, ObjectDisplayOptions options)
}
else
{
return
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
}
}
internal
static
string
FormatLiteral
(
uint
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
uint
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
pooledBuilder
=
PooledStringBuilder
.
GetInstance
();
var
sb
=
pooledBuilder
.
Builder
;
...
...
@@ -411,7 +411,7 @@ internal static string FormatLiteral(uint value, ObjectDisplayOptions options)
}
else
{
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
));
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
));
}
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
))
...
...
@@ -422,7 +422,7 @@ internal static string FormatLiteral(uint value, ObjectDisplayOptions options)
return
pooledBuilder
.
ToStringAndFree
();
}
internal
static
string
FormatLiteral
(
long
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
long
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
pooledBuilder
=
PooledStringBuilder
.
GetInstance
();
var
sb
=
pooledBuilder
.
Builder
;
...
...
@@ -434,7 +434,7 @@ internal static string FormatLiteral(long value, ObjectDisplayOptions options)
}
else
{
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
));
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
));
}
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
))
...
...
@@ -445,7 +445,7 @@ internal static string FormatLiteral(long value, ObjectDisplayOptions options)
return
pooledBuilder
.
ToStringAndFree
();
}
internal
static
string
FormatLiteral
(
ulong
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
ulong
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
pooledBuilder
=
PooledStringBuilder
.
GetInstance
();
var
sb
=
pooledBuilder
.
Builder
;
...
...
@@ -457,7 +457,7 @@ internal static string FormatLiteral(ulong value, ObjectDisplayOptions options)
}
else
{
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
));
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
));
}
if
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
))
...
...
@@ -468,25 +468,30 @@ internal static string FormatLiteral(ulong value, ObjectDisplayOptions options)
return
pooledBuilder
.
ToStringAndFree
();
}
internal
static
string
FormatLiteral
(
double
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
double
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
result
=
value
.
ToString
(
"R"
,
CultureInfo
.
InvariantCulture
);
var
result
=
value
.
ToString
(
"R"
,
GetFormatCulture
(
cultureInfo
)
);
return
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
?
result
+
"D"
:
result
;
}
internal
static
string
FormatLiteral
(
float
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
float
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
result
=
value
.
ToString
(
"R"
,
CultureInfo
.
InvariantCulture
);
var
result
=
value
.
ToString
(
"R"
,
GetFormatCulture
(
cultureInfo
)
);
return
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
?
result
+
"F"
:
result
;
}
internal
static
string
FormatLiteral
(
decimal
value
,
ObjectDisplayOptions
options
)
internal
static
string
FormatLiteral
(
decimal
value
,
ObjectDisplayOptions
options
,
CultureInfo
cultureInfo
=
null
)
{
var
result
=
value
.
ToString
(
CultureInfo
.
InvariantCulture
);
var
result
=
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
);
return
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
?
result
+
"M"
:
result
;
}
private
static
CultureInfo
GetFormatCulture
(
CultureInfo
cultureInfo
)
{
return
cultureInfo
??
CultureInfo
.
InvariantCulture
;
}
}
}
src/Compilers/CSharp/Test/Symbol/SymbolDisplay/ObjectDisplayTests.cs
浏览文件 @
d9bc2bb3
...
...
@@ -283,17 +283,29 @@ public void CultureInvariance()
var
decimalValue
=
new
Decimal
(
12.5
);
Assert
.
Equal
(
"12,5"
,
decimalValue
.
ToString
());
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
None
));
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
));
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
None
,
Thread
.
CurrentThread
.
CurrentCulture
));
Assert
.
Equal
(
"12.5M"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
IncludeTypeSuffix
));
double
doubleValue
=
12.5
;
Assert
.
Equal
(
"12,5"
,
doubleValue
.
ToString
());
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
None
));
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
));
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
None
,
Thread
.
CurrentThread
.
CurrentCulture
));
Assert
.
Equal
(
"12.5D"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
IncludeTypeSuffix
));
float
singleValue
=
12.5F
;
Assert
.
Equal
(
"12,5"
,
singleValue
.
ToString
());
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
None
));
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
));
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
None
,
Thread
.
CurrentThread
.
CurrentCulture
));
Assert
.
Equal
(
"12.5F"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
IncludeTypeSuffix
));
int
intValue
=
12
;
Assert
.
Equal
(
"12"
,
intValue
.
ToString
());
Assert
.
Equal
(
"12"
,
ObjectDisplay
.
FormatLiteral
(
intValue
,
ObjectDisplayOptions
.
None
));
Assert
.
Equal
(
"12"
,
ObjectDisplay
.
FormatLiteral
(
intValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
));
Assert
.
Equal
(
"12"
,
ObjectDisplay
.
FormatLiteral
(
intValue
,
ObjectDisplayOptions
.
None
,
Thread
.
CurrentThread
.
CurrentCulture
));
}
finally
{
...
...
src/Compilers/VisualBasic/Portable/SymbolDisplay/ObjectDisplay.vb
浏览文件 @
d9bc2bb3
...
...
@@ -161,27 +161,27 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
If
(
c
=
"
""
"
,
"
""""
"
,
c
)
End
Function
Friend
Function
FormatLiteral
(
value
As
SByte
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
SByte
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
)
Then
Return
"&H"
&
If
(
value
>=
0
,
value
.
ToString
(
"X2"
),
CInt
(
value
).
ToString
(
"X8"
))
Else
Return
value
.
ToString
(
CultureInfo
.
InvariantCulture
)
Return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
)
End
If
End
Function
Friend
Function
FormatLiteral
(
value
As
Byte
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Byte
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
UseHexadecimalNumbers
)
Then
Return
"&H"
&
value
.
ToString
(
"X2"
)
Else
Return
value
.
ToString
(
CultureInfo
.
InvariantCulture
)
Return
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
)
End
If
End
Function
Friend
Function
FormatLiteral
(
value
As
Short
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Short
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -191,7 +191,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
If
(
value
>=
0
,
value
.
ToString
(
"X4"
),
CInt
(
value
).
ToString
(
"X8"
)))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -201,7 +201,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
UShort
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
UShort
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -211,7 +211,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
value
.
ToString
(
"X4"
))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -221,7 +221,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
Integer
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Integer
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -231,7 +231,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
value
.
ToString
(
"X8"
))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -241,7 +241,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
UInteger
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
UInteger
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -251,7 +251,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
value
.
ToString
(
"X8"
))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -261,7 +261,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
Long
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Long
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -271,7 +271,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
value
.
ToString
(
"X16"
))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -281,7 +281,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
ULong
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
ULong
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
pooledBuilder
=
PooledStringBuilder
.
GetInstance
()
...
...
@@ -291,7 +291,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
sb
.
Append
(
"&H"
)
sb
.
Append
(
value
.
ToString
(
"X16"
))
Else
sb
.
Append
(
value
.
ToString
(
CultureInfo
.
InvariantCulture
))
sb
.
Append
(
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
))
End
If
If
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
)
Then
...
...
@@ -301,26 +301,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
pooledBuilder
.
ToStringAndFree
()
End
Function
Friend
Function
FormatLiteral
(
value
As
Double
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Double
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
result
=
value
.
ToString
(
"R"
,
CultureInfo
.
InvariantCulture
)
Dim
result
=
value
.
ToString
(
"R"
,
GetFormatCulture
(
cultureInfo
)
)
Return
If
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
),
result
&
"R"
,
result
)
End
Function
Friend
Function
FormatLiteral
(
value
As
Single
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Single
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
result
=
value
.
ToString
(
"R"
,
CultureInfo
.
InvariantCulture
)
Dim
result
=
value
.
ToString
(
"R"
,
GetFormatCulture
(
cultureInfo
)
)
Return
If
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
),
result
&
"F"
,
result
)
End
Function
Friend
Function
FormatLiteral
(
value
As
Decimal
,
options
As
ObjectDisplayOptions
)
As
String
Friend
Function
FormatLiteral
(
value
As
Decimal
,
options
As
ObjectDisplayOptions
,
Optional
cultureInfo
As
CultureInfo
=
Nothing
)
As
String
ValidateOptions
(
options
)
Dim
result
=
value
.
ToString
(
CultureInfo
.
InvariantCulture
)
Dim
result
=
value
.
ToString
(
GetFormatCulture
(
cultureInfo
)
)
Return
If
(
options
.
IncludesOption
(
ObjectDisplayOptions
.
IncludeTypeSuffix
),
result
&
"D"
,
result
)
End
Function
...
...
@@ -497,6 +497,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay
Return
Nothing
End
Function
Private
Function
GetFormatCulture
(
cultureInfo
As
CultureInfo
)
As
CultureInfo
Return
If
(
cultureInfo
,
CultureInfo
.
InvariantCulture
)
End
Function
<
Conditional
(
"DEBUG"
)
>
Private
Sub
ValidateOptions
(
options
As
ObjectDisplayOptions
)
' This option is not supported and has no meaning in Visual Basic...should not be passed...
...
...
src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/ObjectDisplayTests.vb
浏览文件 @
d9bc2bb3
...
...
@@ -209,14 +209,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Dim
decimalValue
As
New
Decimal
(
12.5
)
Assert
.
Equal
(
"12,5"
,
decimalValue
.
ToString
())
Assert
.
Equal
(
"12.5"
,
FormatPrimitive
(
decimalValue
))
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
))
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
decimalValue
,
ObjectDisplayOptions
.
None
,
CurrentThread
.
CurrentCulture
))
Dim
doubleValue
As
Double
=
12.5
Assert
.
Equal
(
"12,5"
,
doubleValue
.
ToString
())
Assert
.
Equal
(
"12.5"
,
FormatPrimitive
(
doubleValue
))
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
))
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
doubleValue
,
ObjectDisplayOptions
.
None
,
CurrentThread
.
CurrentCulture
))
Dim
singleValue
As
Single
=
12.5
Assert
.
Equal
(
"12,5"
,
singleValue
.
ToString
())
Assert
.
Equal
(
"12.5"
,
FormatPrimitive
(
singleValue
))
Assert
.
Equal
(
"12.5"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
None
,
CultureInfo
.
InvariantCulture
))
Assert
.
Equal
(
"12,5"
,
ObjectDisplay
.
FormatLiteral
(
singleValue
,
ObjectDisplayOptions
.
None
,
CurrentThread
.
CurrentCulture
))
Finally
CurrentThread
.
CurrentCulture
=
originalCulture
End
Try
...
...
@@ -287,4 +294,4 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
End
Class
End
Namespace
\ No newline at end of file
End
Namespace
src/Scripting/CSharp/Hosting/ObjectFormatter/CSharpObjectFormatter.cs
浏览文件 @
d9bc2bb3
...
...
@@ -5,6 +5,7 @@
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.Scripting.Hosting
;
using
System.Globalization
;
namespace
Microsoft.CodeAnalysis.CSharp.Scripting.Hosting
{
...
...
@@ -65,57 +66,57 @@ internal override string FormatLiteral(char c, bool quote, bool includeCodePoint
internal
override
string
FormatLiteral
(
sbyte
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
byte
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
short
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
ushort
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
int
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
uint
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
long
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
ulong
value
,
bool
useHexadecimalNumbers
=
false
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
));
return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
double
value
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
);
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
float
value
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
);
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
decimal
value
)
{
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
);
return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
);
}
internal
override
string
FormatLiteral
(
DateTime
value
)
...
...
src/Scripting/CSharpTest/CommandLineRunnerTests.cs
浏览文件 @
d9bc2bb3
...
...
@@ -81,6 +81,65 @@ public void Await()
> "
,
runner
.
Console
.
Out
.
ToString
());
}
[
Fact
]
[
WorkItem
(
7133
)]
public
void
TestDisplayResultsWithCurrentUICulture
()
{
var
runner
=
CreateRunner
(
input
:
@"using static System.Globalization.CultureInfo;
DefaultThreadCurrentUICulture = GetCultureInfo(""en-GB"")
Math.PI
DefaultThreadCurrentUICulture = GetCultureInfo(""de-DE"")
Math.PI
"
);
runner
.
RunInteractive
();
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
$@"Microsoft (R) Visual C# Interactive Compiler version
{
CompilerVersion
}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> using static System.Globalization.CultureInfo;
> DefaultThreadCurrentUICulture = GetCultureInfo(""en-GB"")
[en-GB]
> Math.PI
3.1415926535897931
> DefaultThreadCurrentUICulture = GetCultureInfo(""de-DE"")
[de-DE]
> Math.PI
3,1415926535897931
>"
,
runner
.
Console
.
Out
.
ToString
());
// Tests that DefaultThreadCurrentUICulture is respected and not DefaultThreadCurrentCulture.
runner
=
CreateRunner
(
input
:
@"using static System.Globalization.CultureInfo;
DefaultThreadCurrentUICulture = GetCultureInfo(""en-GB"")
DefaultThreadCurrentCulture = GetCultureInfo(""en-GB"")
Math.PI
DefaultThreadCurrentCulture = GetCultureInfo(""de-DE"")
Math.PI
"
);
runner
.
RunInteractive
();
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
$@"Microsoft (R) Visual C# Interactive Compiler version
{
CompilerVersion
}
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> using static System.Globalization.CultureInfo;
> DefaultThreadCurrentUICulture = GetCultureInfo(""en-GB"")
[en-GB]
> DefaultThreadCurrentCulture = GetCultureInfo(""en-GB"")
[en-GB]
> Math.PI
3.1415926535897931
> DefaultThreadCurrentCulture = GetCultureInfo(""de-DE"")
[de-DE]
> Math.PI
3.1415926535897931
>"
,
runner
.
Console
.
Out
.
ToString
());
}
[
Fact
]
public
void
Void
()
{
...
...
src/Scripting/Core/Hosting/ObjectFormatter/ObjectFormatter.cs
浏览文件 @
d9bc2bb3
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
...
...
@@ -336,7 +337,7 @@ private int CurrentRemaining
public
void
AppendLine
()
{
// remove line length limit so that we can insert a new line even
// remove line length limit so that we can insert a new line even
// if the previous one hit maxed out the line limit:
_currentLimit
=
_lengthLimit
;
...
...
@@ -529,9 +530,13 @@ internal virtual string FormatMethodSignature(MethodBase method)
/// </summary>
internal
virtual
bool
IsHiddenMember
(
MemberInfo
member
)
=>
false
;
internal
static
CultureInfo
UIFormatCulture
=>
CultureInfo
.
CurrentUICulture
;
internal
static
ObjectDisplayOptions
GetObjectDisplayOptions
(
bool
useHexadecimalNumbers
)
{
return
useHexadecimalNumbers
?
ObjectDisplayOptions
.
UseHexadecimalNumbers
:
ObjectDisplayOptions
.
None
;
return
useHexadecimalNumbers
?
ObjectDisplayOptions
.
UseHexadecimalNumbers
:
ObjectDisplayOptions
.
None
;
}
/// <summary>
...
...
src/Scripting/VisualBasic/Hosting/ObjectFormatter/VisualBasicObjectFormatter.vb
浏览文件 @
d9bc2bb3
...
...
@@ -61,47 +61,47 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.Hosting
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
SByte
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Byte
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Short
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
UShort
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Integer
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
UInteger
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Long
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
ULong
,
Optional
useHexadecimalNumbers
As
Boolean
=
False
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
))
Return
ObjectDisplay
.
FormatLiteral
(
value
,
GetObjectDisplayOptions
(
useHexadecimalNumbers
)
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Double
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
)
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Single
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
)
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
FormatLiteral
(
value
As
Decimal
)
As
String
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
)
Return
ObjectDisplay
.
FormatLiteral
(
value
,
ObjectDisplayOptions
.
None
,
UIFormatCulture
)
End
Function
Friend
Overrides
Function
GetPrimitiveTypeName
(
type
As
SpecialType
)
As
String
...
...
@@ -246,4 +246,3 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.Hosting
End
Class
End
Namespace
src/Scripting/VisualBasicTest/CommandLineRunnerTests.vb
浏览文件 @
d9bc2bb3
...
...
@@ -126,6 +126,57 @@ Type ""#help"" for more information.
«Red»
(1) : error BC2017: could not find library '://invalidfilepath'
«Gray»
>"
,
runner
.
Console
.
Out
.
ToString
())
End
Sub
<
Fact
()
>
<
WorkItem
(
7133
)
>
Public
Sub
TestDisplayResultsWithCurrentUICulture
()
Dim
runner
=
CreateRunner
(
args
:
=
{},
input
:
=
"Imports System.Globalization
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
? System.Math.PI
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
de-DE
""
)
? System.Math.PI"
)
runner
.
RunInteractive
()
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
"Microsoft (R) Visual Basic Interactive Compiler version "
+
CompilerVersion
+
"
Copyright (C) Microsoft Corporation. All rights reserved.
Type
""
#help
""
for more information.
> Imports System.Globalization
> System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
> ? System.Math.PI
3.1415926535897931
> System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
de-DE
""
)
> ? System.Math.PI
3,1415926535897931
>"
,
runner
.
Console
.
Out
.
ToString
())
' Tests that DefaultThreadCurrentUICulture is respected and not DefaultThreadCurrentCulture.
runner
=
CreateRunner
(
args
:
=
{},
input
:
=
"Imports System.Globalization
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
? System.Math.PI
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(
""
de-DE
""
)
? System.Math.PI"
)
runner
.
RunInteractive
()
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
"Microsoft (R) Visual Basic Interactive Compiler version "
+
CompilerVersion
+
"
Copyright (C) Microsoft Corporation. All rights reserved.
Type
""
#help
""
for more information.
> Imports System.Globalization
> System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
> System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(
""
en-GB
""
)
> ? System.Math.PI
3.1415926535897931
> System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(
""
de-DE
""
)
> ? System.Math.PI
3.1415926535897931
>"
,
runner
.
Console
.
Out
.
ToString
())
End
Sub
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录