Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
9f5e8fd9
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
9f5e8fd9
编写于
6月 01, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add json converters for core Add-Using type.
上级
0e986170
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
39 deletion
+68
-39
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
...emote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
+36
-5
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
...iceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
+3
-3
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
...orkspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
+29
-31
未找到文件。
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.RoslynOnly.cs
浏览文件 @
9f5e8fd9
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
System
;
using
System
;
using
System.Collections.Immutable
;
using
System.Collections.Immutable
;
using
Microsoft.CodeAnalysis.Packaging
;
using
Microsoft.CodeAnalysis.TodoComments
;
using
Microsoft.CodeAnalysis.TodoComments
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
Roslyn.Utilities
;
using
Roslyn.Utilities
;
...
@@ -12,13 +13,14 @@ internal partial class AggregateJsonConverter : JsonConverter
...
@@ -12,13 +13,14 @@ internal partial class AggregateJsonConverter : JsonConverter
{
{
partial
void
AppendRoslynSpecificJsonConverters
(
ImmutableDictionary
<
Type
,
JsonConverter
>.
Builder
builder
)
partial
void
AppendRoslynSpecificJsonConverters
(
ImmutableDictionary
<
Type
,
JsonConverter
>.
Builder
builder
)
{
{
builder
.
Add
(
typeof
(
TodoCommentDescriptor
),
new
TodoCommentDescriptorJsonConverter
());
Add
(
builder
,
new
TodoCommentDescriptorJsonConverter
());
builder
.
Add
(
typeof
(
TodoComment
),
new
TodoCommentJsonConverter
());
Add
(
builder
,
new
TodoCommentJsonConverter
());
Add
(
builder
,
new
PackageSourceJsonConverter
());
}
}
private
class
TodoCommentDescriptorJsonConverter
:
BaseJsonConverter
<
TodoCommentDescriptor
>
private
class
TodoCommentDescriptorJsonConverter
:
BaseJsonConverter
<
TodoCommentDescriptor
>
{
{
protected
override
TodoCommentDescriptor
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TodoCommentDescriptor
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
@@ -48,7 +50,7 @@ protected override void WriteValue(JsonWriter writer, TodoCommentDescriptor desc
...
@@ -48,7 +50,7 @@ protected override void WriteValue(JsonWriter writer, TodoCommentDescriptor desc
private
class
TodoCommentJsonConverter
:
BaseJsonConverter
<
TodoComment
>
private
class
TodoCommentJsonConverter
:
BaseJsonConverter
<
TodoComment
>
{
{
protected
override
TodoComment
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TodoComment
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
@@ -79,5 +81,34 @@ protected override void WriteValue(JsonWriter writer, TodoComment todoComment, J
...
@@ -79,5 +81,34 @@ protected override void WriteValue(JsonWriter writer, TodoComment todoComment, J
writer
.
WriteEndObject
();
writer
.
WriteEndObject
();
}
}
}
}
private
class
PackageSourceJsonConverter
:
BaseJsonConverter
<
PackageSource
>
{
protected
override
PackageSource
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
var
name
=
ReadProperty
<
string
>(
reader
);
var
source
=
ReadProperty
<
string
>(
reader
);
Contract
.
ThrowIfFalse
(
reader
.
Read
());
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
EndObject
);
return
new
PackageSource
(
name
,
source
);
}
protected
override
void
WriteValue
(
JsonWriter
writer
,
PackageSource
source
,
JsonSerializer
serializer
)
{
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"name"
);
writer
.
WriteValue
(
source
.
Name
);
writer
.
WritePropertyName
(
"source"
);
writer
.
WriteValue
(
source
.
Source
);
writer
.
WriteEndObject
();
}
}
}
}
}
}
\ No newline at end of file
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.SolutionIdConverters.cs
浏览文件 @
9f5e8fd9
...
@@ -49,7 +49,7 @@ protected static void WriteIdAndName(JsonWriter writer, Guid id, string debugNam
...
@@ -49,7 +49,7 @@ protected static void WriteIdAndName(JsonWriter writer, Guid id, string debugNam
private
class
SolutionIdJsonConverter
:
WorkspaceIdJsonConverter
<
SolutionId
>
private
class
SolutionIdJsonConverter
:
WorkspaceIdJsonConverter
<
SolutionId
>
{
{
protected
override
SolutionId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
SolutionId
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
return
SolutionId
.
CreateFromSerialized
(
id
,
debugName
);
return
SolutionId
.
CreateFromSerialized
(
id
,
debugName
);
...
@@ -61,7 +61,7 @@ protected override void WriteValue(JsonWriter writer, SolutionId solutionId, Jso
...
@@ -61,7 +61,7 @@ protected override void WriteValue(JsonWriter writer, SolutionId solutionId, Jso
private
class
ProjectIdJsonConverter
:
WorkspaceIdJsonConverter
<
ProjectId
>
private
class
ProjectIdJsonConverter
:
WorkspaceIdJsonConverter
<
ProjectId
>
{
{
protected
override
ProjectId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
ProjectId
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
var
(
id
,
debugName
)
=
ReadFromJsonObject
(
reader
);
return
ProjectId
.
CreateFromSerialized
(
id
,
debugName
);
return
ProjectId
.
CreateFromSerialized
(
id
,
debugName
);
...
@@ -73,7 +73,7 @@ protected override void WriteValue(JsonWriter writer, ProjectId projectId, JsonS
...
@@ -73,7 +73,7 @@ protected override void WriteValue(JsonWriter writer, ProjectId projectId, JsonS
private
class
DocumentIdJsonConverter
:
WorkspaceIdJsonConverter
<
DocumentId
>
private
class
DocumentIdJsonConverter
:
WorkspaceIdJsonConverter
<
DocumentId
>
{
{
protected
override
DocumentId
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
DocumentId
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
...
src/Workspaces/Remote/ServiceHub/Shared/RoslynJsonConverter.cs
浏览文件 @
9f5e8fd9
...
@@ -20,52 +20,54 @@ private AggregateJsonConverter()
...
@@ -20,52 +20,54 @@ private AggregateJsonConverter()
}
}
public
override
bool
CanConvert
(
Type
objectType
)
public
override
bool
CanConvert
(
Type
objectType
)
{
=>
_map
.
ContainsKey
(
objectType
);
return
_map
.
ContainsKey
(
objectType
);
}
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
=>
_map
[
objectType
].
ReadJson
(
reader
,
objectType
,
existingValue
,
serializer
);
return
_map
[
objectType
].
ReadJson
(
reader
,
objectType
,
existingValue
,
serializer
);
}
public
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
public
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
{
=>
_map
[
value
.
GetType
()].
WriteJson
(
writer
,
value
,
serializer
);
_map
[
value
.
GetType
()].
WriteJson
(
writer
,
value
,
serializer
);
}
// this type is shared by multiple teams such as Razor, LUT and etc which have either
separated/shared/shim repo
// this type is shared by multiple teams such as Razor, LUT and etc which have either
// s
o some types might not available to those context. this partial method let us add Roslyn specific types
// s
eparated/shared/shim repo so some types might not available to those context. this
// without breaking them
//
partial method let us add Roslyn specific types
without breaking them
partial
void
AppendRoslynSpecificJsonConverters
(
ImmutableDictionary
<
Type
,
JsonConverter
>.
Builder
builder
);
partial
void
AppendRoslynSpecificJsonConverters
(
ImmutableDictionary
<
Type
,
JsonConverter
>.
Builder
builder
);
private
ImmutableDictionary
<
Type
,
JsonConverter
>
CreateConverterMap
()
private
ImmutableDictionary
<
Type
,
JsonConverter
>
CreateConverterMap
()
{
{
var
builder
=
ImmutableDictionary
.
CreateBuilder
<
Type
,
JsonConverter
>();
var
builder
=
ImmutableDictionary
.
CreateBuilder
<
Type
,
JsonConverter
>();
builder
.
Add
(
typeof
(
Checksum
),
new
ChecksumJsonConverter
());
Add
(
builder
,
new
ChecksumJsonConverter
());
builder
.
Add
(
typeof
(
SolutionId
),
new
SolutionIdJsonConverter
());
Add
(
builder
,
new
SolutionIdJsonConverter
());
builder
.
Add
(
typeof
(
ProjectId
),
new
ProjectIdJsonConverter
());
Add
(
builder
,
new
ProjectIdJsonConverter
());
builder
.
Add
(
typeof
(
DocumentId
),
new
DocumentIdJsonConverter
());
Add
(
builder
,
new
DocumentIdJsonConverter
());
builder
.
Add
(
typeof
(
TextSpan
),
new
TextSpanJsonConverter
());
Add
(
builder
,
new
TextSpanJsonConverter
());
builder
.
Add
(
typeof
(
SymbolKey
),
new
SymbolKeyJsonConverter
());
Add
(
builder
,
new
TextChangeJsonConverter
());
Add
(
builder
,
new
SymbolKeyJsonConverter
());
AppendRoslynSpecificJsonConverters
(
builder
);
AppendRoslynSpecificJsonConverters
(
builder
);
return
builder
.
ToImmutable
();
return
builder
.
ToImmutable
();
}
}
private
static
void
Add
<
T
>(
ImmutableDictionary
<
Type
,
JsonConverter
>.
Builder
builder
,
BaseJsonConverter
<
T
>
converter
)
{
builder
.
Add
(
typeof
(
T
),
converter
);
}
private
abstract
class
BaseJsonConverter
<
T
>
:
JsonConverter
private
abstract
class
BaseJsonConverter
<
T
>
:
JsonConverter
{
{
public
sealed
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
T
)
==
objectType
;
public
sealed
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
T
)
==
objectType
;
public
sealed
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
public
sealed
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
=>
ReadValue
(
reader
,
objectType
,
existingValue
,
serializer
);
=>
ReadValue
(
reader
,
serializer
);
public
sealed
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
public
sealed
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
=>
WriteValue
(
writer
,
(
T
)
value
,
serializer
);
=>
WriteValue
(
writer
,
(
T
)
value
,
serializer
);
protected
abstract
T
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
);
protected
abstract
T
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
);
protected
abstract
void
WriteValue
(
JsonWriter
writer
,
T
value
,
JsonSerializer
serializer
);
protected
abstract
void
WriteValue
(
JsonWriter
writer
,
T
value
,
JsonSerializer
serializer
);
protected
static
U
ReadProperty
<
U
>(
JsonSerializer
serializer
,
JsonReader
reader
)
protected
static
U
ReadProperty
<
U
>(
JsonSerializer
serializer
,
JsonReader
reader
)
...
@@ -91,7 +93,7 @@ protected static U ReadProperty<U>(JsonReader reader)
...
@@ -91,7 +93,7 @@ protected static U ReadProperty<U>(JsonReader reader)
private
class
TextSpanJsonConverter
:
BaseJsonConverter
<
TextSpan
>
private
class
TextSpanJsonConverter
:
BaseJsonConverter
<
TextSpan
>
{
{
protected
override
TextSpan
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TextSpan
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
@@ -121,7 +123,7 @@ protected override void WriteValue(JsonWriter writer, TextSpan span, JsonSeriali
...
@@ -121,7 +123,7 @@ protected override void WriteValue(JsonWriter writer, TextSpan span, JsonSeriali
private
class
TextChangeJsonConverter
:
BaseJsonConverter
<
TextChange
>
private
class
TextChangeJsonConverter
:
BaseJsonConverter
<
TextChange
>
{
{
protected
override
TextChange
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
TextChange
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
{
{
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
Contract
.
ThrowIfFalse
(
reader
.
TokenType
==
JsonToken
.
StartObject
);
...
@@ -157,27 +159,23 @@ protected override void WriteValue(JsonWriter writer, TextChange change, JsonSer
...
@@ -157,27 +159,23 @@ protected override void WriteValue(JsonWriter writer, TextChange change, JsonSer
private
class
SymbolKeyJsonConverter
:
BaseJsonConverter
<
SymbolKey
>
private
class
SymbolKeyJsonConverter
:
BaseJsonConverter
<
SymbolKey
>
{
{
protected
override
SymbolKey
ReadValue
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
protected
override
SymbolKey
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
=>
new
SymbolKey
((
string
)
reader
.
Value
);
=>
new
SymbolKey
((
string
)
reader
.
Value
);
protected
override
void
WriteValue
(
JsonWriter
writer
,
SymbolKey
value
,
JsonSerializer
serializer
)
protected
override
void
WriteValue
(
JsonWriter
writer
,
SymbolKey
value
,
JsonSerializer
serializer
)
=>
writer
.
WriteValue
(
value
.
ToString
());
=>
writer
.
WriteValue
(
value
.
ToString
());
}
}
private
class
ChecksumJsonConverter
:
JsonConverter
private
class
ChecksumJsonConverter
:
BaseJsonConverter
<
Checksum
>
{
{
public
override
bool
CanConvert
(
Type
objectType
)
=>
typeof
(
Checksum
)
==
objectType
;
protected
override
Checksum
ReadValue
(
JsonReader
reader
,
JsonSerializer
serializer
)
public
override
object
ReadJson
(
JsonReader
reader
,
Type
objectType
,
object
existingValue
,
JsonSerializer
serializer
)
{
{
var
value
=
(
string
)
reader
.
Value
;
var
value
=
(
string
)
reader
.
Value
;
return
value
==
null
?
null
:
new
Checksum
(
Convert
.
FromBase64String
(
value
));
return
value
==
null
?
null
:
new
Checksum
(
Convert
.
FromBase64String
(
value
));
}
}
public
override
void
WriteJson
(
JsonWriter
writer
,
object
value
,
JsonSerializer
serializer
)
protected
override
void
WriteValue
(
JsonWriter
writer
,
Checksum
value
,
JsonSerializer
serializer
)
{
=>
writer
.
WriteValue
(
value
?.
ToString
());
writer
.
WriteValue
(
value
?.
ToString
());
}
}
}
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录