在csharp中访问一个类到另一个类的值

时间:2017-09-29 13:06:37

标签: c# class interface web-performance

我有两个类,但我想从类LastFridayDate到类Buildversion的值字符串'version'。

各位大家好,我有两个班级,但我想从类LastFridayDate到类Buildversion的值字符串'version'。

无法访问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)
        {

        }
    }

}

1 个答案:

答案 0 :(得分:0)

您需要将其公开,我建议您使用属性并在某处初始化它。就像在构造函数中或自动初始化。

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