我有一个我创建的API,目前在C#中成功使用。我正在尝试创建一个与VB.NET中的API交互的示例(这样没有C#经验的QA仍然可以利用它来创建自动化测试)。
在C#中,我执行以下操作
[TestingForm(FormName= "Land Lines", CaseType= _caseType
, Application= ApplicationNameCodes.WinRDECode, HasActions= true)]
public class LandLines : RDEMainForm
{
// .. Irrelevant Code .. //
private const string _caseType = "Land Lines";
}
作为没有VB.Net经验的人,我创建了以下内容以尝试模仿它
<TestingForm(Application:=ApplicationNames.WinRDE, FormName:=FORM_NAME, CaseType:=CASE_TYPE, HasActions:=True, IncludeBaseClassActions:=False)>
Public Class Permits
Inherits TestingBase
#Region "Constants"
Private Const FORM_NAME As String = "Permits" 'Display name for the test class (in the editor)
Private Const CASE_TYPE As String = "permits" 'Unique code for this test class, used when reading/saving test plans
#End Region
End Class
这给了我一个编译时错误,因为它声称未定义FORM_NAME
和CASE_TYPE
,即使该类已在其中定义。
如何在类属性中使用类中定义的常量?
答案 0 :(得分:2)
我真的很惊讶C#示例编译(但我确实检查过它)。
在VB.Net中,这种类型的访问(即使在属性中类型之外的私有成员)也是不合法的。相反,您需要将其设为Friend
并限定其访问权限
<TestingForm(Application:=ApplicationNames.WinRDE, FormName:=Permits.FORM_NAME, CaseType:=Permits.CASE_TYPE, HasActions:=True, IncludeBaseClassActions:=False)>
Public Class Permits
Inherits TestingBase
Friend Const FORM_NAME As String = "Permits" 'Display name for the test class (in the editor)
FriendConst CASE_TYPE As String = "permits" 'Unique code for this test class, used when reading/saving test plans
End Class