I have the following code:
Type type = Type.GetType("System.Int16");
object number = Convert.ChangeType("-9", type); //m_value = 3096
MethodInfo method = typeof(Math).GetMethod("Abs", new[] { type });
object resultWithoutCast = method.Invoke(null, new[] { number }); //m_value = 3096
var resultWithCast = (Int16)resultWithoutCast; //9
I'm not sure I know what "m_value" is. My guess is a memory location? What I'm trying to accomplish here is to get the value 9 from resultWithoutCast object, dynamically, without having to cast to Int16.
Thoughts?
Aucun commentaire:
Enregistrer un commentaire