Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4676df79
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,发现更多精彩内容 >>
提交
4676df79
编写于
5月 31, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make json converters strongly typed.
上级
ea7f125b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
59 deletion
+78
-59
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
...emote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
+6
-14
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
...iceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
+13
-27
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
...orkspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
+59
-18
未找到文件。
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
浏览文件 @
4676df79
...
...
@@ -16,11 +16,9 @@ internal partial class AggregateJsonConverter : JsonConverter
builder
.
Add
(
typeof
(
TodoComment
),
new
TodoCommentJsonConverter
());
}
private
class
TodoCommentDescriptorJsonConverter
:
BaseJsonConverter
private
class
TodoCommentDescriptorJsonConverter
:
BaseJsonConverter
<
TodoCommentDescriptor
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
TodoCommentDescriptor
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TodoCommentDescriptor
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
...
@@ -34,10 +32,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return
new
TodoCommentDescriptor
(
text
,
(
int
)
priority
);
}
p
ublic
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
p
rotected
override
void
WriteValue
(
JsonWriter
writer
,
TodoCommentDescriptor
descriptor
,
JsonSerializer
serializer
)
{
var
descriptor
=
(
TodoCommentDescriptor
)
value
;
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"text"
);
...
...
@@ -50,11 +46,9 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
}
private
class
TodoCommentJsonConverter
:
BaseJsonConverter
private
class
TodoCommentJsonConverter
:
BaseJsonConverter
<
TodoComment
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
TodoComment
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TodoComment
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
...
@@ -69,10 +63,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return
new
TodoComment
(
descriptor
,
message
,
(
int
)
position
);
}
p
ublic
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
p
rotected
override
void
WriteValue
(
JsonWriter
writer
,
TodoComment
todoComment
,
JsonSerializer
serializer
)
{
var
todoComment
=
(
TodoComment
)
value
;
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"descriptor"
);
...
...
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
浏览文件 @
4676df79
...
...
@@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.Remote
{
internal
partial
class
AggregateJsonConverter
:
JsonConverter
{
private
abstract
class
WorkspaceIdJsonConverter
:
BaseJsonConverter
private
abstract
class
WorkspaceIdJsonConverter
<
T
>
:
BaseJsonConverter
<
T
>
{
protected
(
Guid
,
string
)
ReadFromJsonObject
(
JsonReader
reader
)
{
...
...
@@ -47,45 +47,33 @@ protected static void WriteIdAndName(JsonWriter writer, Guid id, string debugNam
}
}
private
class
SolutionIdJsonConverter
:
WorkspaceIdJsonConverter
private
class
SolutionIdJsonConverter
:
WorkspaceIdJsonConverter
<
SolutionId
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
SolutionId
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
SolutionId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
return
SolutionId
.
CreateFromSerialized
(
id
,
debugName
);
}
public
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
{
var
solutionId
=
(
SolutionId
)
value
;
WriteToJsonObject
(
writer
,
solutionId
.
Id
,
solutionId
.
DebugName
);
}
protected
override
void
WriteValue
(
JsonWriter
writer
,
SolutionId
solutionId
,
JsonSerializer
serializer
)
=>
WriteToJsonObject
(
writer
,
solutionId
.
Id
,
solutionId
.
DebugName
);
}
private
class
ProjectIdJsonConverter
:
WorkspaceIdJsonConverter
private
class
ProjectIdJsonConverter
:
WorkspaceIdJsonConverter
<
ProjectId
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
ProjectId
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
ProjectId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
return
ProjectId
.
CreateFromSerialized
(
id
,
debugName
);
}
public
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
{
var
projectId
=
(
ProjectId
)
value
;
WriteToJsonObject
(
writer
,
projectId
.
Id
,
projectId
.
DebugName
);
}
protected
override
void
WriteValue
(
JsonWriter
writer
,
ProjectId
projectId
,
JsonSerializer
serializer
)
=>
WriteToJsonObject
(
writer
,
projectId
.
Id
,
projectId
.
DebugName
);
}
private
class
DocumentIdJsonConverter
:
WorkspaceIdJsonConverter
private
class
DocumentIdJsonConverter
:
WorkspaceIdJsonConverter
<
DocumentId
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
DocumentId
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
DocumentId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
...
@@ -99,10 +87,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return
DocumentId
.
CreateFromSerialized
(
projectId
,
id
,
debugName
);
}
p
ublic
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
p
rotected
override
void
WriteValue
(
JsonWriter
writer
,
DocumentId
documentId
,
JsonSerializer
serializer
)
{
var
documentId
=
(
DocumentId
)
value
;
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"projectId"
);
...
...
@@ -114,4 +100,4 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
}
}
}
}
\ No newline at end of file
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
浏览文件 @
4676df79
...
...
@@ -55,34 +55,43 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
return
builder
.
ToImmutable
();
}
private
abstract
class
BaseJsonConverter
:
JsonConverter
private
abstract
class
BaseJsonConverter
<
T
>
:
JsonConverter
{
protected
static
T
ReadProperty
<
T
>(
JsonSerializer
serializer
,
JsonReader
reader
)
public
sealed
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
T
)
==
objectType
;
public
sealed
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
=>
ReadValue
(
reader
,
objectType
,
existingValue
,
serializer
);
public
sealed
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
=>
WriteValue
(
writer
,
(
T
)
value
,
serializer
);
protected
abstract
T
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
);
protected
abstract
void
WriteValue
(
JsonWriter
writer
,
T
value
,
JsonSerializer
serializer
);
protected
static
U
ReadProperty
<
U
>(
JsonSerializer
serializer
,
JsonReader
reader
)
{
// read property
Contract
.
ThrowIfFalse
(
reader
.
Read
());
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
PropertyName
);
Contract
.
ThrowIfFalse
(
reader
.
Read
());
return
serializer
.
Deserialize
<
T
>(
reader
);
return
serializer
.
Deserialize
<
U
>(
reader
);
}
protected
static
T
ReadProperty
<
T
>(
JsonReader
reader
)
protected
static
U
ReadProperty
<
U
>(
JsonReader
reader
)
{
// read property
Contract
.
ThrowIfFalse
(
reader
.
Read
());
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
PropertyName
);
Contract
.
ThrowIfFalse
(
reader
.
Read
());
return
(
T
)
reader
.
Value
;
return
(
U
)
reader
.
Value
;
}
}
private
class
TextSpanJsonConverter
:
BaseJsonConverter
private
class
TextSpanJsonConverter
:
BaseJsonConverter
<
TextSpan
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
TextSpan
)
==
objectType
;
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TextSpan
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
...
@@ -96,10 +105,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
return
new
TextSpan
((
int
)
start
,
(
int
)
length
);
}
p
ublic
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
p
rotected
override
void
WriteValue
(
JsonWriter
writer
,
TextSpan
span
,
JsonSerializer
serializer
)
{
var
span
=
(
TextSpan
)
value
;
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"start"
);
...
...
@@ -112,15 +119,49 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
}
private
class
SymbolKeyJsonConverter
:
BaseJsonConverter
private
class
TextChangeJsonConverter
:
BaseJsonConverter
<
TextChange
>
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
SymbolKey
)
==
objectType
;
protected
override
TextChange
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
// all integer is long
var
start
=
ReadProperty
<
long
>(
reader
);
var
length
=
ReadProperty
<
long
>(
reader
);
var
newText
=
ReadProperty
<
string
>(
reader
);
Contract
.
ThrowIfFalse
(
reader
.
Read
());
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
EndObject
);
return
new
TextChange
(
new
TextSpan
((
int
)
start
,
(
int
)
length
),
newText
);
}
protected
override
void
WriteValue
(
JsonWriter
writer
,
TextChange
change
,
JsonSerializer
serializer
)
{
var
span
=
change
.
Span
;
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"start"
);
writer
.
WriteValue
(
span
.
Start
);
writer
.
WritePropertyName
(
"length"
);
writer
.
WriteValue
(
span
.
Length
);
writer
.
WritePropertyName
(
"newText"
);
writer
.
WriteValue
(
change
.
NewText
);
writer
.
WriteEndObject
();
}
}
private
class
SymbolKeyJsonConverter
:
BaseJsonConverter
<
SymbolKey
>
{
protected
override
SymbolKey
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
=>
new
SymbolKey
((
string
)
reader
.
Value
);
p
ublic
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
=>
writer
.
WriteValue
(
value
.
ToString
());
p
rotected
override
void
WriteValue
(
JsonWriter
writer
,
SymbolKey
value
,
JsonSerializer
serializer
)
=>
writer
.
WriteValue
(
value
.
ToString
());
}
private
class
ChecksumJsonConverter
:
JsonConverter
...
...
@@ -139,4 +180,4 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
}
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录