I want to use reflection to look at all types in a .dll and generate a .proto file for everyone that has a ProtoContract attribute. I am going to use .proto files to create C ++ classes, so my C # code can interact with some C ++. This code will scan the DLL to find types with the ProtoContract attribute, but I don’t know how to dynamically pass this type to GetProto ().
string file = @"C:\bungie\networking\shared\online\output\bin\Test\Xetrov\Xetrov.Core\Xetrov.Core.dll";
var assembly = Assembly.LoadFile(file);
foreach (var type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic)
{
continue;
}
object[] attributes = type.GetCustomAttributes(true);
if(attributes.Where(att => att is ProtoBuf.ProtoContractAttribute).Any())
{
string protoDefinition = ProtoBuf.Serializer.GetProto<T>();
}
}
Any ideas how I can do this? Or is the best way to generate .proto files for all types?
Thank!!
source
share