G
Guest
When I compile the following code with the C++ compiler version
14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line
'cl -W4 -clrldSyntax test.cpp' at run time I get a Null Reference Exception
due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual
Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is
generated.
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public __gc class AttributesSample
{
public:
void Mymethod (int, [Out] String** str2m, String**)
{
*str2m = S"in Mymethod";
}
};
void PrintAttributes(Type* attribType, int iAttribValue)
{
if (attribType->IsEnum)
{
FieldInfo* fields[] =
attribType->GetFields(static_cast<BindingFlags>(BindingFlags:ublic |
BindingFlags::Static));
for (int i = 0; i < fields->Length; i++)
{
int fieldvalue = *dynamic_cast<Int32*>(fields->GetValue(0));
//exception here
if ((fieldvalue & iAttribValue) == fieldvalue)
{
Console::WriteLine(fields->Name);
}
}
}
}
int main()
{
Type* MyType = Type::GetType(S"AttributesSample");
MethodBase* Mymethodbase = MyType->GetMethod(S"Mymethod");
MethodAttributes Myattributes = Mymethodbase->Attributes;
PrintAttributes(__typeof(System::Reflection::MethodAttributes), (int)
Myattributes);
return 0;
}
Is this a bug?
14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line
'cl -W4 -clrldSyntax test.cpp' at run time I get a Null Reference Exception
due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual
Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is
generated.
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
public __gc class AttributesSample
{
public:
void Mymethod (int, [Out] String** str2m, String**)
{
*str2m = S"in Mymethod";
}
};
void PrintAttributes(Type* attribType, int iAttribValue)
{
if (attribType->IsEnum)
{
FieldInfo* fields[] =
attribType->GetFields(static_cast<BindingFlags>(BindingFlags:ublic |
BindingFlags::Static));
for (int i = 0; i < fields->Length; i++)
{
int fieldvalue = *dynamic_cast<Int32*>(fields->GetValue(0));
//exception here
if ((fieldvalue & iAttribValue) == fieldvalue)
{
Console::WriteLine(fields->Name);
}
}
}
}
int main()
{
Type* MyType = Type::GetType(S"AttributesSample");
MethodBase* Mymethodbase = MyType->GetMethod(S"Mymethod");
MethodAttributes Myattributes = Mymethodbase->Attributes;
PrintAttributes(__typeof(System::Reflection::MethodAttributes), (int)
Myattributes);
return 0;
}
Is this a bug?