I have the following class:
public class Happy : IHappy
{
//public some properties and etc... { get; set; }
public bool IsHappy()
{
//Do something...
}
}
And it is a property in another class:
public class Exemplo
{
public IHappy Happy { get; set; }
// Other properties and methods etc...
}
Now inside my executable I'm creating an example instance by reflection. And I want to access the Happy.IsHappy() method through it. It is possible? I'm trying something like this:
DoThiks(string CalledClass) // where CalledClass = "Exemplo"
{
//Instantiate the object Exemplo (working fine)
Type ExemploType = Type.GetType(CalledClass + ",namespace");
ConstructorInfo ExemploConstructor = ExemploType.GetConstructor(Type.EmptyTypes);
object ExemploClassObject = ExemploConstructor.Invoke(new object[] { });
//Problem is here.
//Try instantiate the Happy property to call his method...
PropertyInfo HappyPropery = ExemploType.GetProperty("Happy"); //PropertyInfo can call methods?
MethodInfo methodHappy = HappyPropery.GetType().GetMethod("IsHappy");
methodHappy.Invoke(HappyPropery, null);
}
As you may have noticed, I'm kind of lost in this second part... Could anyone save me?