2011-09-27 135 views
2

我有一个API,我创建并成功地在C#中使用。我试图创建一个在VB.NET中与API交互的例子(这样,没有C#经验的QA仍然可以利用它来创建自动化测试)。如何在VB.Net的类属性中访问私有常量?

在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_NAMECASE_TYPE未定义,即使该类已在里面定义它。

如何在类属性中使用类中定义的常量?

回答

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 
+0

这就像一个魅力!谢谢, – KallDrexx