您好我如何使用没有属性的protobuf?因为我需要将二进制序列化更改为protobuf。我如何使用RuntypeModel?
var assembly = Assembly.GetAssembly();
var types = assembly.GetTypes();
foreach (var t in types.Where(x => x.Namespace.Contains("PlainEntities")))
{
Console.WriteLine("Processing {0}", t.FullName);
var meta = RuntimeTypeModel.Default.Add(t, false);
var index = 1;
// FIND ANY DERIVED CLASS FOR THE ENTITY
foreach (var d in types.Where(x => x.IsSubclassOf(t)))
{
var i = index++;
Console.WriteLine("\tSubtype: {0} - #{1}", d.Name, i);
meta.AddSubType(i, d);
}
// THEN ADD THE PROPERTIES
foreach (var p in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => x.GetSetMethod() != null))
{
var i = index++;
Console.WriteLine("\tProperty: {0} - #{1}", p.Name, i);
meta.AddField(i, p.Name);
}
}
项目在哪里必须是?
由于