【问题标题】:Access a value from one class to another in csharp在 csharp 中从一个类访问另一个类的值
【发布时间】:2017-09-29 13:06:37
【问题描述】:

我有两个类,但我想将 LastFridayDate 类中的值字符串“版本”转换为 Buildversion 类。

大家好,我有两个类,但我想将 LastFridayDate 类中的值字符串“版本”转换为 Buildversion 类。

我无法访问字符串版本,任何人的帮助。

我的代码:

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)
        {

        }
    }

}

【问题讨论】:

标签: c# class interface web-performance


【解决方案1】:

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

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

【讨论】:

  • 我仍然无法使用公共字符串版本 {get;放; }.
  • 我尝试了一个完全通用的答案,现在我需要更多详细信息。你到底想在哪里使用Version
  • 我想在 m_loadTest_LoadTestFinished 方法中使用 Buildversion 类的版本。
猜你喜欢
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 2023-04-07
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多