次の方法で共有


TestPropertyAttribute.Name プロパティ

テスト プロパティの名前を取得します。

名前空間:  Microsoft.VisualStudio.TestTools.UnitTesting
アセンブリ:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 内)

構文

'宣言
Public ReadOnly Property Name As String
    Get
public string Name { get; }
public:
property String^ Name {
    String^ get ();
}
member Name : string
function get Name () : String

プロパティ値

型: System.String
テスト プロパティの名前。

TestProperty の名前を取得する方法を次の例に示します。

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;
using System.Reflection;

namespace TestProperty
{
   [TestClass]
   public class TestPropertyTest
   {
      [TestMethod()]
      [TestProperty("MyProperty1", "Big")]
      [TestProperty("MyProperty2", "Small")]
      public void MyTestMethod()
      {
         // Get the current type
         Type t = GetType();

         MethodInfo mi = t.GetMethod("MyTestMethod");
         Type MyType = typeof(TestPropertyAttribute);
         object[] attributes = mi.GetCustomAttributes(MyType, false);

         for (int i = 0; i < attributes.Length; i++)
         {
            string name = ((TestPropertyAttribute)attributes[i]).Name;
            string val = ((TestPropertyAttribute)attributes[i]).Value;

            string mystring = string.Format("Property Name: {0}, Value: {1}", name, val);
            MessageBox.Show(mystring);
         }
      }
   }
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

TestPropertyAttribute クラス

Microsoft.VisualStudio.TestTools.UnitTesting 名前空間

MethodInfo