当前位置: 代码迷 >> VC >> 能不能用PropertyInfo.SetValue对枚举数组开展赋值
  详细解决方案

能不能用PropertyInfo.SetValue对枚举数组开展赋值

热度:9395   发布时间:2013-02-25 00:00:00.0
能不能用PropertyInfo.SetValue对枚举数组进行赋值。
我实现了除一般类型数组的赋值。
#ifdef ELSE
#define ELSE else
#else
#define ELSE
#endif

#define BUILDARR(type,fun) ELSE if(Type::GetType(type_name) == __typeof(type)) \
{ \
type arrf __gc[] = new type __gc[arr->Length]; \
for(int k = 0; k < arr->Length; k++) \
{ \
arrf[k] = fun (arr->Item[k]); \
} \
arrobj = arrf; \
}

上面宏定义后,就可以用
BUILDARR(float,Convert::ToSingle);
BUILDARR(unsigned short,Convert::ToUInt16);
prop->SetValue(to, arrobj, NULL);
等来对各类型数组进行PropertyInfo.SetValue。
但是到了枚举那里,就不行了。
Type* t = prop->PropertyType->GetElementType();
if(t->IsEnum)
{
                                Object* arre = prop->GetValue(to, NULL);

Object* arrf __gc[] = new Object* __gc[arr->Length];
for(int k = 0; k < arr->Length; k++)
{
arrf[k] = Enum::Parse(t,arr->Item[k]->ToString());
}
//arrobj = arrf;

arre = arrf;

//prop->SetValue(to, NULL, NULL);
prop->SetValue(to, arre, NULL);

总是提示无法转换,高手来解决一把.谢了
------解决方案--------------------------------------------------------
我自己搞定了~~
------解决方案--------------------------------------------------------
待分享...