我在https://codepaste.net/mngm23下找到了关于C#的avro示例:
{
"type": "record",
"name": "Person",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "address",
"type": {
"type": "record",
"name": "Address",
"fields": [
{ "name": "address", "type": "string" },
{ "name": "zipcode", "type": "string" }]
}
}
]
}
插入项目的C#代码如下所示:
var schema = RecordSchema.Parse(schemaStr) as RecordSchema;
// pick out the address schema so we can assign to that
var addrSchema = schema["address"].Schema as RecordSchema;
var person = new Generic.GenericRecord(schema);
person.Add("name", "RIck");
person.Add("age", 45);
person.Add("company", "West Wind");
// create a child record
var address = new GenericRecord(addrSchema);
address.Add("address", "32 Kaiea");
address.Add("zipcode", "96779");
person.Add("address", address);
var st = new FileStream(STR_Ctempavrobin,FileMode.OpenOrCreate,FileAccess.Write,FileShare.Write);
Avro.IO.Encoder enc = new BinaryEncoder(st);
var dwr = new Generic.DefaultWriter(schema);
dwr.Write<GenericRecord>(person, enc);
st.Close();
我无法弄清楚,如何调整架构和csharp代码来实现&#34;地址&#34;一系列的地址。我试过跟随,但我没有设法获得adressesList模式。
{
"type": "record",
"name": "Person",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "addressList",
"type": "array",
"items" : {
"type": "record",
"name": "Address",
"fields": [
{ "name": "address", "type": "string" },
{ "name": "zipcode", "type": "string" }]
}
}
]
}
如何在C#中向数组添加项目呢?