2

I'm wondering what is the best way to represent a table that should contain those fields in C# bond format?

  • string FirstName
  • string LastName
  • string Email
  • bool Registered
  • DateTime DateJoined
  • char Gender
  • List<string> Favorites
  • string City
  • string State
  • unit16 Zip
  • string Country
  • List<string> FrequentPagesURLs

And I want to have something similar to that format

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

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

I'm not sure what is the best way to represent char, DateTime, and List<string> in C# bond format to use them in creating table in Object store.

chwarr
  • 6,777
  • 1
  • 30
  • 57
Nehad Hazem
  • 59
  • 1
  • 7

2 Answers2

2

According to the official documentation for Bond, there are the following types:

Basic type: bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64, float, double, string, wstring.

Container: blob, list, vector, set, map, nullable.

User-defined type: enum, struct or bonded where T is a struct.

However, the documentation also explains how to generate the DateTime, char, etc. if you are using bond to generate C# code. That is to use the following in your CLI command:

gbc c# --using="DateTime=System.DateTime" date_time.bond

The using parameter is where you put type aliases, such as "char=System.Char;DateTime=System.DateTime".

I don't know if this adequately helps you, please let me know if you need anything else.

Sources:

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

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

Cutler Cox
  • 33
  • 1
  • 5
  • I got very confused in the part for generating DateTime, char, and so on. I'm not sure how to write this in the schema file in the format I mentioned above. It will be so great if you can provide example given the table that I need to create. – Nehad Hazem Aug 03 '17 at 21:36
  • There's an existing question about [how to represent `TimeSpan`](https://stackoverflow.com/questions/39492730/implementing-an-equivalent-of-c-sharp-timespan-in-microsoft-bond), which points to an [example about `DateTime`](https://github.com/Microsoft/bond/tree/master/examples/cs/core/date_time). – chwarr Aug 04 '17 at 00:13
2

I would model the gender field as an enum, as this is more explicit than a char; the DateTime field as a uint64, but use a type converter to turn this into a DateTime struct in C#; and the List<string> field as a 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;
    ...
}

You may want to consider modeling the DateJoined field as a string/blob and using a type converter to turn it into a DateTimeOffset struct in C#, depending on your needs.

chwarr
  • 6,777
  • 1
  • 30
  • 57