public class Test{
public string name{get;set}
public short age{get;set;}
}
....
var type = typeof(Test);
var ins = Activator.CreateInstance(type);
type.InvokeMember("name", BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty, null, ins ,new object[] { "alibaba" });
type.InvokeMember("age", BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.SetField | BindingFlags.SuppressChangeType, null, ins ,new object[] { 2 });
...
An exception of method 'age' not found throw when running,if I change the type of 'age' to int or other 32+ numeric type, it works
Whether or not the InvokeMember does not support type of short,int16 ect. Or I might change another way to assign value.
Any help is appreciated
Can you please try this. It worked for me.