Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
f82d7c98
F
fsharp
项目概览
dotNET Platform
/
fsharp
12 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f82d7c98
编写于
8月 24, 2016
作者:
L
liboz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
print public fields
上级
6f425432
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
20 addition
and
11 deletion
+20
-11
src/utils/sformat.fs
src/utils/sformat.fs
+20
-11
未找到文件。
src/utils/sformat.fs
浏览文件 @
f82d7c98
...
...
@@ -709,8 +709,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
// pprinter: anyL - support functions
// --------------------------------------------------------------------
let
getProperty
(
obj
:
obj
)
name
=
let
ty
=
obj
.
GetType
()
let
getProperty
(
ty
:
Type
)
(
obj
:
obj
)
name
=
#
if
FX_ATLEAST_PORTABLE
let
prop
=
ty
.
GetProperty
(
name
,
(
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
))
if
isNotNull
prop
then
prop
.
GetValue
(
obj
,[||])
...
...
@@ -732,6 +731,9 @@ namespace Microsoft.FSharp.Text.StructuredFormat
ty
.
InvokeMember
(
name
,
(
BindingFlags
.
GetProperty
|||
BindingFlags
.
Instance
|||
BindingFlags
.
Public
|||
BindingFlags
.
NonPublic
),
null
,
obj
,
[|
|],
CultureInfo
.
InvariantCulture
)
#
endif
#
endif
let
getField
obj
(
fieldInfo
:
FieldInfo
)
=
fieldInfo
.
GetValue
(
obj
)
let
formatChar
isChar
c
=
match
c
with
|
'\''
when
isChar
->
"
\\\'
"
...
...
@@ -862,7 +864,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
let
postText
=
m
.
Groups
.[
"post"
].
Value
// Everything after the closing bracket
let
prop
=
replaceEscapedBrackets
(
m
.
Groups
.[
"prop"
].
Value
)
// Unescape everything between the opening and closing brackets
match
catchExn
(
fun
()
->
getProperty
x
prop
)
with
match
catchExn
(
fun
()
->
getProperty
ty
x
prop
)
with
|
Choice2Of2
e
->
Some
(
wordL
(
"<StructuredFormatDisplay exception: "
+
e
.
Message
+
">"
))
|
Choice1Of2
alternativeObj
->
try
...
...
@@ -1102,8 +1104,11 @@ namespace Microsoft.FSharp.Text.StructuredFormat
#
else
let
props
=
ty
.
GetProperties
(
BindingFlags
.
GetField
|||
BindingFlags
.
Instance
|||
BindingFlags
.
Public
)
#
endif
let
props
=
props
|>
Array
.
filter
(
fun
pi
->
let
fields
=
ty
.
GetFields
(
BindingFlags
.
Instance
|||
BindingFlags
.
Public
)
let
propsAndFields
=
props
|>
Array
.
map
(
fun
i
->
i
:>
MemberInfo
)
|>
Array
.
append
(
Array
.
map
(
fun
i
->
i
:>
MemberInfo
)
fields
)
|>
Array
.
filter
(
fun
pi
->
// check if property is annotated with System.Diagnostics.DebuggerBrowsable(Never).
// Its evaluation may have unexpected side effects and\or block printing.
match
Seq
.
toArray
(
pi
.
GetCustomAttributes
(
typeof
<
System
.
Diagnostics
.
DebuggerBrowsableAttribute
>,
false
))
with
...
...
@@ -1114,17 +1119,21 @@ namespace Microsoft.FSharp.Text.StructuredFormat
// massively reign in deep printing of properties
let
nDepth
=
depthLim
/
10
#
if
FX_ATLEAST_PORTABLE
System
.
Array
.
Sort
((
props
),{
new
System
.
Collections
.
Generic
.
IComparer
<
Property
Info
>
with
member
this
.
Compare
(
p1
,
p2
)
=
compare
(
p1
.
Name
)
(
p2
.
Name
)
}
);
System
.
Array
.
Sort
((
props
AndFields
),{
new
System
.
Collections
.
Generic
.
IComparer
<
Member
Info
>
with
member
this
.
Compare
(
p1
,
p2
)
=
compare
(
p1
.
Name
)
(
p2
.
Name
)
}
);
#
else
System
.
Array
.
Sort
((
props
:>
System
.
Array
),{
new
System
.
Collections
.
IComparer
with
member
this
.
Compare
(
p1
,
p2
)
=
compare
((
p1
:?>
PropertyInfo
).
Name
)
((
p2
:?>
Property
Info
).
Name
)
}
);
System
.
Array
.
Sort
((
props
AndFields
:>
System
.
Array
),{
new
System
.
Collections
.
IComparer
with
member
this
.
Compare
(
p1
,
p2
)
=
compare
((
p1
:?>
MemberInfo
).
Name
)
((
p2
:?>
Member
Info
).
Name
)
}
);
#
endif
if
props
.
Length
=
0
||
(
nDepth
<=
0
)
then
basicL
if
props
AndFields
.
Length
=
0
||
(
nDepth
<=
0
)
then
basicL
else
basicL
---
(
props
(
props
AndFields
|>
Array
.
toList
|>
List
.
map
(
fun
p
->
(
p
.
Name
,(
try
Some
(
objL
nDepth
Precedence
.
BracketIfTuple
(
getProperty
obj
p
.
Name
))
with
_
->
None
)))
|>
List
.
map
(
fun
m
->
(
m
.
Name
,
(
try
Some
(
objL
nDepth
Precedence
.
BracketIfTuple
(
getProperty
ty
obj
m
.
Name
))
with
_
->
try
Some
(
objL
nDepth
Precedence
.
BracketIfTuple
(
getField
obj
(
m
:?>
FieldInfo
)))
with
_
->
None
)))
|>
makePropertiesL
)
|
_
->
basicL
|
UnitValue
->
countNodes
1
;
measureL
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录