Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4d5c7862
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,发现更多精彩内容 >>
提交
4d5c7862
编写于
7月 11, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Serialize without unsafe code.
上级
27768b04
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
14 deletion
+34
-14
src/Compilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
...mpilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
+3
-0
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
+6
-8
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
+25
-6
未找到文件。
src/Compilers/Core/CodeAnalysisTest/ObjectSerializationTests.cs
浏览文件 @
4d5c7862
...
...
@@ -1036,6 +1036,9 @@ private void TestRoundTripChar(Char ch)
public
void
TestRoundTripGuid
()
{
TestRoundTripGuid
(
Guid
.
Empty
);
TestRoundTripGuid
(
new
Guid
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
));
TestRoundTripGuid
(
new
Guid
(
0
b10000000000000000000000000000000
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
));
TestRoundTripGuid
(
new
Guid
(
0
b10000000000000000000000000000000
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
));
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
TestRoundTripGuid
(
Guid
.
NewGuid
());
...
...
src/Compilers/Core/Portable/Serialization/ObjectReader.cs
浏览文件 @
4d5c7862
...
...
@@ -126,15 +126,13 @@ public void Dispose()
public
unsafe
Guid
ReadGuid
()
{
Debug
.
Assert
(
sizeof
(
Guid
)
==
16
);
Debug
.
Assert
(
sizeof
(
long
)
==
8
);
Guid
guid
;
long
*
pGuid
=
(
long
*)&
guid
;
pGuid
[
0
]
=
ReadInt64
();
pGuid
[
1
]
=
ReadInt64
();
var
accessor
=
new
ObjectWriter
.
GuidAccessor
{
Low64
=
ReadInt64
(),
High64
=
ReadInt64
()
};
return
g
uid
;
return
accessor
.
G
uid
;
}
public
object
ReadValue
()
...
...
src/Compilers/Core/Portable/Serialization/ObjectWriter.cs
浏览文件 @
4d5c7862
...
...
@@ -119,13 +119,32 @@ public void Dispose()
public
void
WriteUInt16
(
ushort
value
)
=>
_writer
.
Write
(
value
);
public
void
WriteString
(
string
value
)
=>
WriteStringValue
(
value
);
public
unsafe
void
WriteGuid
(
Guid
guid
)
/// <summary>
/// Used so we can easily grab the low/high 64bits of a guid for serialization.
/// </summary>
[
StructLayout
(
LayoutKind
.
Explicit
)]
internal
struct
GuidAccessor
{
unsafe
static
GuidAccessor
()
{
Debug
.
Assert
(
sizeof
(
Guid
)
==
16
);
Debug
.
Assert
(
sizeof
(
long
)
==
8
);
}
[
FieldOffset
(
0
)]
public
Guid
Guid
;
[
FieldOffset
(
0
)]
public
long
Low64
;
[
FieldOffset
(
8
)]
public
long
High64
;
}
public
void
WriteGuid
(
Guid
guid
)
{
Debug
.
Assert
(
sizeof
(
Guid
)
==
16
);
Debug
.
Assert
(
sizeof
(
long
)
==
8
);
long
*
pGuid
=
(
long
*)&
guid
;
WriteInt64
(
pGuid
[
0
]);
WriteInt64
(
pGuid
[
1
]);
var
accessor
=
new
GuidAccessor
{
Guid
=
guid
};
WriteInt64
(
accessor
.
Low64
);
WriteInt64
(
accessor
.
High64
);
}
public
void
WriteValue
(
object
value
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录