如何禁用通过覆盖 Ranorex (c#) 发生的警告

How to disable warning that occurred by overriding in Ranorex (c#)

我尝试在 Ranorex Studio 中使用覆盖(使用 c# 语言)

public class DropListActions
{
     public void SimpleSelectByInnerText(string text, bool close){
     }
}
public class CheckBoxDropListWithInputField : DropListActions
{
     //overriding
     public void SimpleSelectByInnerText(string text, bool close){
     }
}

一切正常,但在报告中显示警告:

'****************.CheckBoxDropListWithInputField.SimpleSelectByInnerText(string, bool)' hides inherited member '****************.DropListActions.SimpleSelectByInnerText(string, bool)'. Use the new keyword if hiding was intended. (CS0108) - C:\*****\Ranorex\RanorexStudio Projects\*****\DropListActions.cs:117,18

例如,在 java 中,所有由 @Override 注释标记的重写方法。也许在 c# 中有一个合适的方法来做到这一点?如何跳过这些警告消息?

Both the base class and the derived class have a method with the same name (SimpleSelectByInnerText). The compiler is telling you that the method in the derived class is "hiding" the method in the base class (you're not overriding it because only virtual or abstract methods can be overridden).

To get rid of this warning you can use the new keyword which tells the compiler that you intend to "hide" the base method:

public class CheckBoxDropListWithInputField : DropListActions
{
     public new void SimpleSelectByInnerText(string text, bool close)
     {   //  ^ new keyword here before the return type   
     }
}

Alternatively, you could use override and mark the method in the base class as virtual:

public class DropListActions
{
     public virtual void SimpleSelectByInnerText(string text, bool close)
     {
     }
}

public class CheckBoxDropListWithInputField : DropListActions
{
     public override void SimpleSelectByInnerText(string text, bool close)
     {
     }
}

See What’s the difference between override and new? by Jon Skeet and Compiler Warning (level 2) CS0108 for more info.