2017-09-29 13 views
-1

私は2つのクラスを持っていますが、私はクラスLastFridayDateからBuildversionクラスへの値の文字列 'version'を求めています。あるクラスから別のクラスに値をアクセスするには

こんにちは皆、私は2つのクラスを持っていますが、私は値クラス 'クラス'から 'クラス'へのバージョンLastFridayDateをBuildversionにしたい。

誰かの助けを借りて、Stringバージョンにアクセスできません。

私のコード:

using System; 
using Microsoft.VisualStudio.TestTools.WebTesting; 
using Microsoft.VisualStudio.TestTools.LoadTesting; 
using System.ComponentModel; 
namespace PTUtil 
{ 

    [System.ComponentModel.DisplayName("GetVersion")] 
    [System.ComponentModel.Description("Get the Build No Version")] 
    public class LastFridayDate : WebTestPlugin 
    { 
     String version; 

     //Setting the version in the usercontext 
     public override void PostWebTest(object sender, PostWebTestEventArgs e) 
     { 
      version = e.WebTest.Context["Param_ClientSoftwareVersion"].ToString(); 
     } 

    } 

    /// Specify a name for use in the user interface. 
    /// The user sees this name in the Add Validation dialog box. 
    [DisplayName("Build Version Processing")] 
    /// Specify a description for use in the user interface 
    /// The user sees this description in the Add Validation dialog box. 
    [Description("Add the build version for a load test")] 
    public class BuildVersion : ILoadTestPlugin 
    { 
     [DisplayName("Comment")] 
     [Description("What the plugin is for")] 
     public string theComment { get; set; } 

     [DisplayName("Test Type")] 
     [Description("M for Manual or A for Automatic")] 
     [DefaultValue("A")] 
     public string connectionStr { get; set; } 

     [DisplayName("Version Context Parameter")] 
     [Description("The Context Parameter for the build version")] 
     [DefaultValue("{{Param_ClientSoftwareVersion}}")] 
     public string Version_param { get; set; } 

     LoadTest m_loadTest; 

     public void Initialize(LoadTest loadTest) 
     { 
      m_loadTest = loadTest; 

      m_loadTest.LoadTestFinished += new EventHandler(m_loadTest_LoadTestFinished); 
     } 

     // Do it *after* the Load Test. 
     //--------------------------------------------------------------------- 

     void m_loadTest_LoadTestFinished(object sender, System.EventArgs e) 
     { 

     } 
    } 

} 
+0

フィールド 'version'には修飾子がありません。この修飾子はデフォルトで非公開にします。パブリック修飾子を使用してそれを表示させる: 'public String version';詳細はこちらhttps://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers – saidfagan

答えて

0

あなたはそれを公開する必要があると私はあなたがプロパティを使用してどこかにそれを初期化することをお勧めします。コンストラクタやauto-initializeのように。

public string Version {get; set; } = String.Empty 
+0

私はまだ使用できません。セット; }。 – laura

+0

私は完全に一般的な答えを試しました、今私は詳細が必要です。どこで 'Version'を使ってみようとしていますか? –

+0

m_loadTest_LoadTestFinishedメソッドのBuildversionクラスのバージョンを使用します。 – laura

関連する問題