class Program
{
static void Main(string[] args)
{
Type t = (new List<MyType>() {new MyType("1"), new MyType("2"), new MyType("3") }).GetType();
TypeInfo pi = t.GetTypeInfo();
PropertyInfo prop = pi.DeclaredProperties.Where(c => c.Name == "Item").FirstOrDefault();
Type tp = prop.PropertyType;
object obj = tp.InvokeMember("", BindingFlags.CreateInstance, null, null, new object[] { "from Invoke" });
object name = tp.InvokeMember("Name", BindingFlags.InvokeMethod, null, obj, null);
}
}
class MyType
{
public MyType()
{
Console.Write("I was born => my name is: ");
}
public MyType(string s) : this()
{
Console.WriteLine(s);
}
public string Name()
{
return "It's me " ;
}
}
on my opinion there is just one way to invoke inner method without casting an object "obj" to the type "tp"
but still it would be better to obtain an object "obj" of properly type.