リフレクションを使用して .dll 内のすべてのタイプを調べ、ProtoContract 属性を持つすべてのタイプの .proto ファイルを生成したいと考えています。.proto ファイルを使用して C++ クラスを生成し、C# コードが一部の C++ と相互運用できるようにします。このコードは .dll を調べて ProtoContract 属性を持つ型を見つけますが、その型を動的に GetProto() に渡す方法がわかりません。
//get assemblies in directory.
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;
}
//Get all the attribute for the type
object[] attributes = type.GetCustomAttributes(true);
//Look for the ProtoContract attribute
if(attributes.Where(att => att is ProtoBuf.ProtoContractAttribute).Any())
{
// We have a type that protobuf can use, generate the .proto file
// How to tell it what type T is?? can't use variable type
string protoDefinition = ProtoBuf.Serializer.GetProto<T>();
}
}
これを達成する方法はありますか?または、すべてのタイプの .proto ファイルを生成するより良い方法はありますか?
ありがとう!!