Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_20853741
flatbuffers
提交
bfcde555
F
flatbuffers
项目概览
qq_20853741
/
flatbuffers
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flatbuffers
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bfcde555
编写于
9月 22, 2020
作者:
D
Derek Bailey
提交者:
GitHub
9月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[C#] Fix and improve project files (#6116)"
This reverts commit
75028163
.
上级
96d5e359
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
132 deletion
+78
-132
docs/source/CsharpUsage.md
docs/source/CsharpUsage.md
+9
-60
net/FlatBuffers/FlatBuffers.Core.csproj
net/FlatBuffers/FlatBuffers.Core.csproj
+19
-0
net/FlatBuffers/FlatBuffers.csproj
net/FlatBuffers/FlatBuffers.csproj
+50
-15
net/FlatBuffers/FlatBuffers.net35.csproj
net/FlatBuffers/FlatBuffers.net35.csproj
+0
-57
未找到文件。
docs/source/CsharpUsage.md
浏览文件 @
bfcde555
...
...
@@ -14,38 +14,14 @@ documentation to build `flatc` and should be familiar with
[
Using the schema compiler
](
@ref
flatbuffers_guide_using_schema_compiler) and
[
Writing a schema
](
@ref
flatbuffers_guide_writing_schema).
## FlatBuffers C
#
code location
## FlatBuffers C
-sharp
code location
The code for the FlatBuffers C# library can be found at
`flatbuffers/net/FlatBuffers`
. You can browse the library on the
[
FlatBuffers GitHub page
](
https://github.com/google/flatbuffers/tree/master/net/
FlatBuffers).
## Building the FlatBuffers C# library
The
`FlatBuffers.csproj`
project contains multitargeting for .NET Standard 2.1,
.NET Standard 2.0, and .NET Framework 4.6 (Unity 2017). Support for .NET
Framework 3.5 (Unity 5) is provided by the
`FlatBuffers.net35.csproj`
project.
In most cases (including Unity 2018 and newer), .NET Standard 2.0 is
recommended.
You can build for a specific framework target when using the cross-platform
[
.NET Core SDK
](
https://dotnet.microsoft.com/download
)
by adding the
`-f`
command line option:
~~~
{.sh}
dotnet build -f netstandard2.0 "FlatBuffers.csproj"
~~~
The
`FlatBuffers.csproj`
project also provides support for enabling various
conditional compiler constants (see "Conditional compiler constants" section
below) using command line options:
~~~
{.sh}
dotnet build -f netstandard2.1 -p:ENABLE_SPAN_T=true -p:UNSAFE_BYTEBUFFER=true "FlatBuffers.csproj"
~~~
## Testing the FlatBuffers C# library
## Testing the FlatBuffers C-sharp libraries
The code to test the libraries can be found at
`flatbuffers/tests`
.
...
...
@@ -55,12 +31,12 @@ tests, open `FlatBuffers.Test.csproj` in [Visual Studio](
https://www.visualstudio.com
)
, and compile/run the project.
Optionally, you can run this using
[
Mono
](
http://www.mono-project.com/
)
instead.
Once you have installed
Mono
, you can run the tests from the command line
Once you have installed
`Mono`
, you can run the tests from the command line
by running the following commands from inside the
`FlatBuffers.Test`
folder:
~~~
{.sh}
mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
mono Assert.exe
mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
mono Assert.exe
~~~
## Using the FlatBuffers C# library
...
...
@@ -98,7 +74,7 @@ Now you can access the data from the `Monster monster`:
Vec3 pos = monster.Pos;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C# code naming follows standard C# style with
PascalCasing
identifiers,
C# code naming follows standard C# style with
`PascalCasing`
identifiers,
e.g.
`GetRootAsMyRootType`
. Also, values (except vectors and unions) are
available as properties instead of parameterless accessor methods.
The performance-enhancing methods to which you can pass an already created
...
...
@@ -157,8 +133,8 @@ around using as little as possible of it. This does make the API clumsier
For times when efficiency is less important a more convenient object based API
can be used (through
`--gen-object-api`
) that is able to unpack & pack a
FlatBuffer into objects and standard
`System.Collections.Generic`
containers,
allowing for convenient
construction, access and mutation.
FlatBuffer into objects and standard
System.Collections.Generic containers, allowing for convenient
construction, access and mutation.
To use:
...
...
@@ -178,7 +154,7 @@ To use:
### Json Serialization
An additional feature of the object API is the ability to allow you to
serialize & deserialize a JSON text.
serialize & deserialize a JSON text.
To use Json Serialization, add
`--cs-gen-json-serializer`
option to
`flatc`
and
add
`Newtonsoft.Json`
nuget package to csproj.
...
...
@@ -196,31 +172,4 @@ add `Newtonsoft.Json` nuget package to csproj.
*
NuGet package Dependency
*
[
Newtonsoft.Json
](
https://github.com/JamesNK/Newtonsoft.Json
)
## Conditional compiler constants
There are three conditional compiler constants that have an impact on
performance/features of the C#
`ByteBuffer`
implementation.
*
`UNSAFE_BYTEBUFFER`
This will use unsafe code to manipulate the underlying byte array. This can
yield a reasonable performance increase.
*
`BYTEBUFFER_NO_BOUNDS_CHECK`
This will disable the bounds check asserts to the byte array. This can yield a
small performance gain in normal code.
*
`ENABLE_SPAN_T`
This will enable reading and writing blocks of memory with a
`Span<T>`
instead
of just
`T[]`
. You can also enable writing directly to shared memory or other
types of memory by providing a custom implementation of
`ByteBufferAllocator`
.
`ENABLE_SPAN_T`
also requires
`UNSAFE_BYTEBUFFER`
to be defined, and requires
.NET Standard 2.1.
Using
`UNSAFE_BYTEBUFFER`
and
`BYTEBUFFER_NO_BOUNDS_CHECK`
together can yield a
performance gain of ~15% for some operations, however doing so is potentially
dangerous. Do so at your own risk!
<br>
net/FlatBuffers/FlatBuffers.Core.csproj
0 → 100644
浏览文件 @
bfcde555
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\**" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Properties\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Properties\**" />
</ItemGroup>
</Project>
net/FlatBuffers/FlatBuffers.csproj
浏览文件 @
bfcde555
<Project Sdk="Microsoft.NET.Sdk">
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"12.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProjectGuid>
{28C00774-1E73-4A75-AD8F-844CD21A064D}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
FlatBuffers
</RootNamespace>
<AssemblyName>
FlatBuffers
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition="'$(UNSAFE_BYTEBUFFER)' == 'true'">
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(BYTEBUFFER_NO_BOUNDS_CHECK)' == 'true'">
<DefineConstants>$(DefineConstants);BYTEBUFFER_NO_BOUNDS_CHECK</DefineConstants>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(ENABLE_SPAN_T)' == 'true'">
<DefineConstants>$(DefineConstants);ENABLE_SPAN_T</DefineConstants>
</PropertyGroup>
</Project>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"ByteBuffer.cs"
/>
<Compile
Include=
"FlatBufferBuilder.cs"
/>
<Compile
Include=
"FlatBufferConstants.cs"
/>
<Compile
Include=
"IFlatbufferObject.cs"
/>
<Compile
Include=
"Offset.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Struct.cs"
/>
<Compile
Include=
"Table.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
net/FlatBuffers/FlatBuffers.net35.csproj
已删除
100644 → 0
浏览文件 @
96d5e359
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"12.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition=
"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProjectGuid>
{28C00774-1E73-4A75-AD8F-844CD21A064D}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
FlatBuffers
</RootNamespace>
<AssemblyName>
FlatBuffers
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\net35
</OutputPath>
<IntermediateOutputPath>
obj\Debug\net35
</IntermediateOutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\net35
</OutputPath>
<IntermediateOutputPath>
obj\Release\net35
</IntermediateOutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"ByteBuffer.cs"
/>
<Compile
Include=
"ByteBufferUtil.cs"
/>
<Compile
Include=
"FlatBufferBuilder.cs"
/>
<Compile
Include=
"FlatBufferConstants.cs"
/>
<Compile
Include=
"IFlatbufferObject.cs"
/>
<Compile
Include=
"Offset.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Struct.cs"
/>
<Compile
Include=
"Table.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录