Generics C+中的泛型类型定义+/CLI

Generics C+中的泛型类型定义+/CLI,generics,c++-cli,Generics,C++ Cli,在C语言中,可以编写 typeof(IInterface<>). typeof(界面)。 C++/CLI中是否有类似的功能 ISYMessageDispatcher<>::typeid ISYMessageDispatcher::typeid 未编译,因为编译器崩溃 当我测试它(使用Visual Studio 2010 SP1)时,这不会使编译器崩溃,只是语法错误 #using <System.dll> int main(void) { Sy

在C语言中,可以编写

typeof(IInterface<>).
typeof(界面)。
C++/CLI中是否有类似的功能

ISYMessageDispatcher<>::typeid
ISYMessageDispatcher::typeid
未编译,因为编译器崩溃

当我测试它(使用Visual Studio 2010 SP1)时,这不会使编译器崩溃,只是语法错误

#using <System.dll>

int main(void)
{
    System::Console::WriteLine( (System::Collections::Generic::List<>::typeid)->ToString() );
    return 0;
}
有关解决方法,请参见当我测试它时(使用Visual Studio 2010 SP1),这不会使编译器崩溃,只是语法错误

#using <System.dll>

int main(void)
{
    System::Console::WriteLine( (System::Collections::Generic::List<>::typeid)->ToString() );
    return 0;
}

有关解决方法,请参见以下适用于我的方法:

auto x = gcnew Generic::List<bool>;
if (x->GetType()->GetGenericTypeDefinition() == Generic::List::typeid)
{
   System::Console::WriteLine("The generic type is " + Generic::List::typeid); // or x->GetType::GetGenericTypeDefinition()
   System::Console::WriteLine("The specific type is " + Generic::List<bool>::typeid); // or x->GetType()
}
auto x=gcnew Generic::List;
如果(x->GetType()->GetGenericTypeDefinition()==Generic::List::typeid)
{
System::Console::WriteLine(“泛型类型为”+generic::List::typeid);//或x->GetType::GetGenericTypeDefinition()
System::Console::WriteLine(“特定类型为”+Generic::List::typeid);//或x->GetType()
}
这就产生了产出

泛型类型为System.Collections.generic.List`1[T]

特定类型为System.Collections.Generic.List`1[System.Boolean]


以下是我的作品:

auto x = gcnew Generic::List<bool>;
if (x->GetType()->GetGenericTypeDefinition() == Generic::List::typeid)
{
   System::Console::WriteLine("The generic type is " + Generic::List::typeid); // or x->GetType::GetGenericTypeDefinition()
   System::Console::WriteLine("The specific type is " + Generic::List<bool>::typeid); // or x->GetType()
}
auto x=gcnew Generic::List;
如果(x->GetType()->GetGenericTypeDefinition()==Generic::List::typeid)
{
System::Console::WriteLine(“泛型类型为”+generic::List::typeid);//或x->GetType::GetGenericTypeDefinition()
System::Console::WriteLine(“特定类型为”+Generic::List::typeid);//或x->GetType()
}
这就产生了产出

泛型类型为System.Collections.generic.List`1[T]

特定类型为System.Collections.Generic.List`1[System.Boolean]


编译器的哪个版本?如果从命令行运行cl.exe,它是否会给出任何错误消息?编译器的哪个版本?如果从命令行运行cl.exe,它是否会给出任何错误消息?因此,在C++/CLI中根本不可能直接访问C#中的泛型类型定义?@Antineutrino:我不知道有任何错误消息。抱歉。因此,在C++/CLI中根本不可能直接访问C#中的泛型类型定义?@Antineutrino:我不知道有什么。很抱歉