2017-08-03 132 views
2

我想知道什么是最好的方式来表示应该包含C#债券格式的这些字段的表?C#债券中可用的数据类型是什么?

  • 串名字
  • 串名字
  • 串电子邮件
  • 布尔注册
  • 日期时间DateJoined
  • 焦炭性别
  • 列表<串>收藏
  • 串城
  • 串国家
  • unit16邮编
  • 串国家
  • 列表<串> FrequentPagesURLs

而且我希望有类似格式的东西

namespace MyProject 
{ 
    struct Key 
    { 
     0: required string Email; 
    } 

    struct Value 
    { 
     0: required string FirstName; 
     1: optional char Gender; 
     . 
     . 
     . 
    } 
} 

我不知道代表char,DateTime和的最佳方式是什么3210以C#bond格式用于在Object store中创建表格。

回答

2

根据对债券的正式文件中,有以下几种类型:

基本类型:BOOL,UINT8,UINT16,UINT32,UINT64,INT8,INT16,INT32,Int64的,浮动,双,字符串,wstring。

容器:blob,list,vector,set,map,nullable。

用户定义类型:enum,struct或bonded其中T是一个结构。

但是,该文档还解释了如何使用bond生成C#代码以生成DateTime,char等。这是使用您的CLI命令如下:

GBC C#--using = “日期时间= System.DateTime的” date_time.bond

的使用参数是你把类型的别名,如作为“char = System.Char; DateTime = System.DateTime”。

我不知道这是否对您有充分的帮助,请让我知道您是否需要其他东西。

来源:

https://microsoft.github.io/bond/manual/compiler.html

https://microsoft.github.io/bond/manual/bond_cs.html

+0

我在生成DateTime,char等部分中感到非常困惑。 我不知道如何以我上面提到的格式在架构文件中编写它。 如果您可以提供示例给出我需要创建的表格,那将会非常棒。 –

+0

关于[如何表示'TimeSpan']存在一个存在的问题(https://stackoverflow.com/questions/39492730/implementing-an-equivalent-of-c-sharp-timespan-in-microsoft-bond)到[DateTime的示例](https://github.com/Microsoft/bond/tree/master/examples/cs/core/date_time)。 – chwarr

2

我的性别字段建模为一个枚举,因为这是不是一个char更加明确;将DateTime字段设置为uint64,但使用a type converter将其变为a DateTime struct in C#;和List<string>字段作为vector<string>

namespace MyProject; 

using DateTime=uint64; 

enum Gender 
{ 
    Unspecified; 
    ... 
} 

struct Favorite { ... } 
struct FrequentPagesURL { ... } 

struct SomeType 
{ 
    ... 
    7: DateTime DateJoined; 
    8: Gender Gender = Unspecified; 
    9: vector<Favorite> Favorites; 
    ... 
    17: vector<FrequentPagesURL> FrequentPagesURLs; 
    ... 
} 

你可能要考虑造型DateJoined字段作为string/blob和使用的类型转换器把它变成一个DateTimeOffset struct在C#中,depending on your needs