child class is not inheriting property from parent

Ask general questions here.
rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

child class is not inheriting property from parent

Post by rkarhe » Fri Nov 01, 2013 12:41 pm

Hello,

I have created wrapper of Ranorex.WebElement something like below.

namespace WObject
{
public class WWebElement : Ranorex.WebElement
{
public WWebElement()
: base()
{
}

public WWebElement(Element element)
: base(element)
{
}

public static implicit operator WWebElement(string path)
{
return new WWebElement(path);
}

public static implicit operator WWebElement(Ranorex.Core.Element element)
{
return new WWebElement(element);
}
}
}

When I am using this wrapper like below

WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling;

it says Cannot implicitly convert type 'Ranorex.WebElement' to 'WObject.WWebElement'. An explicit conversion exists (are you missing a cast?)

Looks like "ele.As<WObject.WWebElement>().NextSibling" is returning parent element (whereas I think it should return child.)

What is the problem here? Why not child 'WObject.WWebElement' has inherited property '.NextSibling'?

Thanks in advance...

rkarhe
Posts: 42
Joined: Thu Jul 28, 2011 5:31 am

Re: child class is not inheriting property from parent

Post by rkarhe » Sun Nov 03, 2013 12:57 am

Any suggestion on this.
I have tried redefining in child like "new public WWebElement NextSibling { get; set; }"
but this returns null object and not next element.

WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling;
//controlToEdit is null when tried redefining NextSibling in child class.

Also I should not need to Redefine this way in child class or should I ? What's the use of inheritance then?

Thanks in advance...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: child class is not inheriting property from parent

Post by Support Team » Mon Nov 04, 2013 4:32 pm

rkarhe wrote:What is the problem here? Why not child 'WObject.WWebElement' has inherited property '.NextSibling'?
The NextSibling is indeed inherited (otherwise you could not call it :D ), but it returns a WebElement, not your newly defined class. So you need to use the As method again to get an instance of your specialized WWebElement adapter back. (Depending on what type the "ele" variable is, you might omit the first usage of the "As" method).
WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling.As<WObject.WWebElement>();
rkarhe wrote: have tried redefining in child like "new public WWebElement NextSibling { get; set; }"
In C#, what you did is not a "redefine", but a new property that is just named "NextSibling" and that hides the base property. Consequently, this new property will just stay "null" forever (unless you assign the property to some value).

Regards,
Alex
Ranorex Team
.
Image