the problem I am currently having is that I am trying to cast to an unknown type and I receive this message from the following code:
The type or namespace name 'thistype' could not be found (are you missing a using directive or an assembly reference?)
String thistype = null;
for (int i = 0; i < items.Length; i++)
{
thistype = typeof(BugManagerQueryOptions).GetProperty(items[i].ToString()).PropertyType.Name;
typeof(BugManagerQueryOptions).GetProperty(items[i].ToString()).SetValue(currentSearch,(thistype)properties[i], null);
}
If you need any more information just ask and any help would be appreciated, thanks. - Chris
You don't need to cast at all, assuming the value of properties[i]
is already actually the right type:
for (int i = 0; i < items.Length; i++)
{
typeof(BugManagerQueryOptions).GetProperty(items[i].ToString())
.SetValue(currentSearch, properties[i], null);
}
If you were trying to invoke a user-defined conversion (e.g. from XElement
to String
) then that's a lot more complicated.
See more on this question at Stackoverflow