我正在用 C++ 为 .Net 开发一个简单的编译器,但是我的包含系统有问题,因此如果它是 void 、 string 、 int ,似乎找不到一种方法来识别我从 dll 调用的方法类型...所以,我的包含系统调用 .net dll 调用
@include System
@include System:Windows:Forms
什么时候生成代码,需要知道,什么样的方法......我想知道是否有人知道一种方法来获取方法的类型,而不使用工具.net
我想到使用它的一种方法:用 C# 或另一种 .net 语言创建一个应用程序来生成一个 TXT,这个 txt 包含方法的名称和它们的正确类型,在编译时,我携带这个 txt 并在编译时方法的类型
但是,我想知道,如果有另一种方式。
关于我谈到的这个程序是:
using namespace System;
using namespace System::IO;
using namespace System::Reflection;
ref class Reflector
{
public:
void LoadAndReflect(String^ assemblyFileName)
{
Assembly^ assembly = Assembly::Load(assemblyFileName);
array<Type^>^ types = assembly->GetTypes();
StreamWriter^ sw = gcnew StreamWriter("mscorlib.txt");
for each(Type^ t in types)
{
array<MethodInfo^>^ methods = t->GetMethods();
for each(MethodInfo^ method in methods)
{
String^ base = method->ReturnType->ToString();
array<String^>^ auxBase = base->Split('.');
if(auxBase->Length > 1)
sw->WriteLine(String::Format("{0} <::> {1}", auxBase[1], method->Name));
else
sw->WriteLine(String::Format("{0} <::> {1}", auxBase[0], method->Name));
}
}
sw->Close();
}
};
int main(array<System::String ^> ^args)
{
Reflector^ ref = gcnew Reflector();
Console::WriteLine("Reflection on {0}", "mscorlib.dll");
ref->LoadAndReflect("mscorlib.dll");
return 0;
}
而且,在编译器时,我打开那个 txt 并得到方法类型