Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
2948bb9a
R
runtime
项目概览
dotNET Platform
/
runtime
大约 1 年 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2948bb9a
编写于
7月 12, 2022
作者:
T
Tamás Turnyánszki
提交者:
GitHub
7月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes #71295 (#71924)
上级
8cb4e934
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
11 deletion
+56
-11
src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs
...ons.Configuration.Json/src/JsonConfigurationFileParser.cs
+24
-11
src/libraries/Microsoft.Extensions.Configuration.Json/tests/ArrayTest.cs
...icrosoft.Extensions.Configuration.Json/tests/ArrayTest.cs
+32
-0
未找到文件。
src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs
浏览文件 @
2948bb9a
...
...
@@ -34,13 +34,13 @@ internal sealed class JsonConfigurationFileParser
{
throw
new
FormatException
(
SR
.
Format
(
SR
.
Error_InvalidTopLevelJSONElement
,
doc
.
RootElement
.
ValueKind
));
}
VisitElement
(
doc
.
RootElement
);
Visit
Object
Element
(
doc
.
RootElement
);
}
return
_data
;
}
private
void
VisitElement
(
JsonElement
element
)
private
void
Visit
Object
Element
(
JsonElement
element
)
{
var
isEmpty
=
true
;
...
...
@@ -52,6 +52,26 @@ private void VisitElement(JsonElement element)
ExitContext
();
}
SetNullIfElementIsEmpty
(
isEmpty
);
}
private
void
VisitArrayElement
(
JsonElement
element
)
{
int
index
=
0
;
foreach
(
JsonElement
arrayElement
in
element
.
EnumerateArray
())
{
EnterContext
(
index
.
ToString
());
VisitValue
(
arrayElement
);
ExitContext
();
index
++;
}
SetNullIfElementIsEmpty
(
isEmpty
:
index
==
0
);
}
private
void
SetNullIfElementIsEmpty
(
bool
isEmpty
)
{
if
(
isEmpty
&&
_paths
.
Count
>
0
)
{
_data
[
_paths
.
Peek
()]
=
null
;
...
...
@@ -65,18 +85,11 @@ private void VisitValue(JsonElement value)
switch
(
value
.
ValueKind
)
{
case
JsonValueKind
.
Object
:
VisitElement
(
value
);
Visit
Object
Element
(
value
);
break
;
case
JsonValueKind
.
Array
:
int
index
=
0
;
foreach
(
JsonElement
arrayElement
in
value
.
EnumerateArray
())
{
EnterContext
(
index
.
ToString
());
VisitValue
(
arrayElement
);
ExitContext
();
index
++;
}
VisitArrayElement
(
value
);
break
;
case
JsonValueKind
.
Number
:
...
...
src/libraries/Microsoft.Extensions.Configuration.Json/tests/ArrayTest.cs
浏览文件 @
2948bb9a
...
...
@@ -254,5 +254,37 @@ public void TrailingCommas()
Assert
.
Equal
(
"9.10.11.12"
,
jsonConfigSource
.
Get
(
"ip:1:0"
));
Assert
.
Equal
(
"13.14.15.16"
,
jsonConfigSource
.
Get
(
"ip:1:1"
));
}
[
Fact
]
public
void
EmptyArrayNotIgnored
()
{
var
json
=
@"{
""ip"": {
""array"": [
],
""object"":{
}
}
}"
;
var
jsonConfigSource
=
new
JsonConfigurationSource
{
FileProvider
=
TestStreamHelpers
.
StringToFileProvider
(
json
)
};
var
configurationBuilder
=
new
ConfigurationBuilder
();
configurationBuilder
.
Add
(
jsonConfigSource
);
var
config
=
configurationBuilder
.
Build
();
var
configurationSection
=
config
.
GetSection
(
"ip"
);
var
ipSectionChildren
=
configurationSection
.
GetChildren
().
ToArray
();
Assert
.
Equal
(
1
,
config
.
GetChildren
().
Count
());
Assert
.
Equal
(
2
,
ipSectionChildren
.
Count
());
Assert
.
Equal
(
"array"
,
ipSectionChildren
[
0
].
Key
);
Assert
.
Null
(
ipSectionChildren
[
0
].
Value
);
Assert
.
Equal
(
"object"
,
ipSectionChildren
[
1
].
Key
);
Assert
.
Null
(
ipSectionChildren
[
1
].
Value
);
Assert
.
Equal
(
0
,
ipSectionChildren
[
0
].
GetChildren
().
Count
());
Assert
.
Equal
(
0
,
ipSectionChildren
[
1
].
GetChildren
().
Count
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录