Hello,
I have a class something like below.
namespace Tool
{
public class uielement : parentuielement
{
protected uielement();
public uielement(Element element);
public static implicit operator uielement(Element element);
public static implicit operator uielement(string path);
public uielement NextGeneration { get; }
}
}
For this class above I have created child as below.
namespace myobject
{
public class Wuielement : Tool.uielement
{
public Wuielement()
: base()
{
}
public Wuielement(Element element)
: base(element)
{
}
public static implicit operator Wuielement(string path)
{
return new Wuielement(path);
}
public static implicit operator Wuielement(Ranorex.Core.Element element)
{
return new Wuielement(element);
}
}
}
Now when I am using this
Ex. myobject.Wuielement edit = ele.As
Here this gives error something like "Cannot Implicitly conver type 'Tool.uielement' to 'myobject.Wuielement'".
Look like the property .NextGeneration is returning parent type (Tool.uielement) whereas it should return 'myobject.Wuielement'
What is the problem here? Why not child 'myobject.Wuielement' has inherited property '.NextGeneration'?
Thanks in advance...
Sachin
VulpesPosted Nov 2, 2013, 8:34 PM
I don't know how you were giving it a value in the parent class but you could do something analogous in the child class.
sachin dimbrePosted Nov 2, 2013, 7:50 PM
Thanks for the reply.
I have tried redefining like
new public Wuielement NextGeneration{ get; set; } . This time is does not give any compilation error but returns null object.
myobject.Wuielement edit = ele.As
//here in above edit is null.
Casting (as you explained) also gives same problem, null.
Do I need to redefine other attributes also everytime in child class?
Regards,
Sachin
VulpesPosted Nov 1, 2013, 12:54 PM
In other words inheritance doesn't change the return type of a property or method.
If the object returned by NextGeneration is actually a Wuielement in this particular case, then you could simply cast it to that type:
myobject.Wuielement edit = (myobject.Wuielement)ele.As
Alternatively, you could redefine NextGeneration in the Wuielement class and hide the base class implementation:
new public Wuielement NextGeneration { get; }