I
Interraptor
Guest
I would like to call TryParse Method with generic types
But after invoke I became a NULL in output variable.
Why and how can I achive this goal?
Thanks
// this class has a property Date
// became a property
var propertyclass = this.GetType().GetProperty("Date");
// became a property type
Type T = propertyclass.PropertyType;
// create a variable of property type for output
object ores = Activator.CreateInstance(T);
// became a method TryParse of type of property
var method = T.GetMethod("TryParse", new[] { typeof(string), T.MakeByRefType() });
// call method with parameters
var result = (bool)method.Invoke(null, new object[] { "01.01.2020", ores });
// get result THE PROBLEM: ores is null
if (result)
{
propertyclass.SetValue(this, ores, null);
}
Continue reading...
But after invoke I became a NULL in output variable.
Why and how can I achive this goal?
Thanks
// this class has a property Date
// became a property
var propertyclass = this.GetType().GetProperty("Date");
// became a property type
Type T = propertyclass.PropertyType;
// create a variable of property type for output
object ores = Activator.CreateInstance(T);
// became a method TryParse of type of property
var method = T.GetMethod("TryParse", new[] { typeof(string), T.MakeByRefType() });
// call method with parameters
var result = (bool)method.Invoke(null, new object[] { "01.01.2020", ores });
// get result THE PROBLEM: ores is null
if (result)
{
propertyclass.SetValue(this, ores, null);
}
Continue reading...