ParameterInfo.IsDefined メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ParameterInfo.IsDefined メソッドの意味・解説 

ParameterInfo.IsDefined メソッド

指定されている型のカスタム属性がこのメンバ定義されているかどうか確認します

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable Function
 IsDefined ( _
    attributeType As Type, _
    inherit As Boolean _
) As Boolean
Dim instance As ParameterInfo
Dim attributeType As Type
Dim inherit As Boolean
Dim returnValue As Boolean

returnValue = instance.IsDefined(attributeType, inherit)
public virtual bool IsDefined (
    Type attributeType,
    bool inherit
)
public:
virtual bool IsDefined (
    Type^ attributeType, 
    bool inherit
)
public boolean IsDefined (
    Type attributeType, 
    boolean inherit
)
public function IsDefined (
    attributeType : Type, 
    inherit : boolean
) : boolean

パラメータ

attributeType

検索する Type オブジェクト

inherit

この型のオブジェクトでは、この引数無視されます。

戻り値
このメンバattributeTypeインスタンス1 つ以上定義されている場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

attributeTypenull 参照 (Visual Basic では Nothing) です。

使用例使用例
'  The following example shows how the attributes related to the parameters
 of methods 
'  of the class can be retrieved at run time. A custom parameter level
 attribute 
'  named 'MyAttribute' is defined. This custom attribute is associated
 with a 
'  parameter of the method 'MyMethod' of 'MyClass1'. This attribute
 is then 
'  retrieved at run time for the parameter of the method of the class
 'MyClass1' 
'  and displayed.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Define a custom attribute with one named parameter.
<AttributeUsage(AttributeTargets.Parameter)> Public Class
 MyAttribute
    Inherits Attribute
    Private myName As String

    Public Sub New(ByVal
 name As String)
        myName = name
    End Sub 'New

    Public ReadOnly Property
 Name() As String
        Get
            Return myName
        End Get
    End Property
End Class 'MyAttribute

' Define a class which has a custom attribute associated with one of
 parameters of a method. 
Public Class MyClass1

    Public Sub MyMethod(<MyAttribute("This
 is an example parameter attribute")> ByVal i
 As Integer)
        Return
    End Sub 'MyMethod
End Class 'MyClass1


Public Class MemberInfo_GetCustomAttributes

    Public Shared Sub Main()
        ' Get the type of the class 'MyClass1'.
        Dim myType As Type = GetType(MyClass1)
        ' Get the members associated with the class 'MyClass1'.
        Dim myMethods As MethodInfo() = myType.GetMethods()

        ' Display the attributes of type 'MyAttribute' for each of the
 parameters of each method of the class 'MyClass1'.
        Dim i As Integer
        For i = 0 To myMethods.Length - 1
            ' Get the parameters for the method.
            Dim myParameters As ParameterInfo()
 = myMethods(i).GetParameters()
            Console.WriteLine(ControlChars.Cr & "The parameters
 for the method {0} that have a custom attribute are : " & ControlChars.Cr,
 myMethods(i))
            Dim j As Integer
            For j = 0 To myParameters.Length
 - 1
                ' Get the attributes of type 'MyAttribute' for each
 parameter.
                Dim myAttributes As [Object]()
 = myParameters(j).GetCustomAttributes(GetType(MyAttribute),
 False)
                If myParameters(j).IsDefined(GetType(MyAttribute),
 False) Then
                    Console.WriteLine(ControlChars.Cr + "The attributes
 for the parameter ""{0}""
 are : " & ControlChars.Cr, myParameters(j).ParameterType)
                    ' Display all the attributes of type 'MyAttribute'
 for a parameter.
                    Dim k As Integer
                    For k = 0 To myAttributes.Length
 - 1
                        Console.WriteLine("The type of the attribute
 is : {0}", myAttributes(k))
                    Next k
                End If
            Next j
        Next i
    End Sub 'Main
End Class 'MemberInfo_GetCustomAttributes
 
// The following example shows how the attributes related to the parameters
 of methods 
// of the class can be retrieved at run time. A custom parameter level
 attribute 
// named 'MyAttribute' is defined. This custom attribute is associated
 with a 
// parameter of the method 'MyMethod' of 'MyClass1'. This attribute
 is then 
// retrieved at run time for the parameter of the method of the class
 'MyClass1' 
// and displayed.

using System;
using System.Reflection;

// Define a custom attribute with one named parameter.
[AttributeUsage(AttributeTargets.Parameter)]
public class MyAttribute : Attribute
{
    private string myName;
    public MyAttribute(string name)
    {
        myName = name;
    }
    public string Name 
    {
        get 
        {
            return myName;
        }
    }
}

// Define a class which has a custom attribute associated with one of
 parameters of a method. 
public class MyClass1
{
    public void MyMethod(
        [MyAttribute("This is an example parameter attribute")]
        int i)
    {
        return;
    }
}

public class MemberInfo_GetCustomAttributes
 
{
    public static void Main()
    {
        // Get the type of the class 'MyClass1'.
        Type myType = typeof(MyClass1);
        // Get the members associated with the class 'MyClass1'.
        MethodInfo[] myMethods = myType.GetMethods();

        // Display the attributes of type 'MyAttribute' for each of
 the parameters of each method of the class 'MyClass1'.
        for(int i = 0; i < myMethods.Length;
 i++)
        {
            // Get the parameters for the method.
            ParameterInfo[] myParameters = myMethods[i].GetParameters();
            Console.WriteLine("\nThe parameters for the method
 \"{0}\" which have an custom attribute are : \n", myMethods[i]);
            for(int j = 0; j < myParameters.Length;
 j++)
            {
                // Get the attributes of type 'MyAttribute' for each
 parameter.
                Object[] myAttributes = myParameters[j].GetCustomAttributes(typeof(MyAttribute),
 false);
                if(myParameters[j].IsDefined(typeof(MyAttribute),
 false))
                {
                    Console.WriteLine("\nThe attributes for
 the parameter \"{0}\" are : \n", myParameters[j].ParameterType);
                    // Display all the attributes of type 'MyAttribute'
 for a parameter.
                    for(int k = 0; k < myAttributes.Length;
 k++)
                        Console.WriteLine("The type of the attribute is : {0}"
,
 myAttributes[k]);
                }
            }
        }  
    }
}
// System::Reflection::ParameterInfo::GetCustomAttributes(Type, bool)
// System::Reflection::ParameterInfo::IsDefined(Type, bool)
/*
   This example shows how the attributes related to the parameters of methods 
   of the class can be retrieved at run time. A custom parameter
 level attribute 
   named 'MyAttribute' is defined. This custom attribute is associated with a 
   parameter of the method 'MyMethod' of 'MyClass1'. This attribute is then 
   retrieved at run time for the parameter of the method of the
 class 'MyClass1' 
   and displayed.
 */
using namespace System;
using namespace System::Reflection;

// Define a custom attribute with one named parameter.

[AttributeUsage(AttributeTargets::Parameter)]
public ref class MyAttribute: public
 Attribute
{
private:
   String^ myName;

public:
   MyAttribute( String^ name )
   {
      myName = name;
   }

   property String^ Name 
   {
      String^ get()
      {
         return myName;
      }
   }
};

// Define a class which has a custom attribute associated with one of
 parameters of a method. 
public ref class MyClass1
{
public:
   void MyMethod( [MyAttribute("This is an example parameter
 attribute")]int i ){}

};

void main()
{
   // Get the type of the class 'MyClass1'.
   Type^ myType = MyClass1::typeid;

   // Get the members associated with the class 'MyClass1'.
   array<MethodInfo^>^myMethods = myType->GetMethods();

   // Display the attributes of type 'MyAttribute' for each of the parameters
 of each method of the class 'MyClass1'.
   for ( int i = 0; i < myMethods->Length;
 i++ )
   {
      // Get the parameters for the method.
      array<ParameterInfo^>^myParameters = myMethods[ i ]->GetParameters();
      Console::WriteLine( "\nThe parameters for the method
 \"{0}\" which have an custom attribute are : \n", myMethods[ i ]
 );
      for ( int j = 0; j < myParameters->Length;
 j++ )
      {
         // Get the attributes of type 'MyAttribute' for each parameter.
         array<Object^>^myAttributes = myParameters[ j ]->GetCustomAttributes(
 MyAttribute::typeid, false );
         if ( myParameters[ j ]->IsDefined( MyAttribute::typeid,
 false ) )
         {
            Console::WriteLine( "\nThe attributes for the
 parameter \"{0}\" are : \n", myParameters[ j ]->ParameterType
 );

            // Display all the attributes of type 'MyAttribute' for
 a parameter.
            for ( int k = 0; k < myAttributes->Length;
 k++ )
               Console::WriteLine( "The type of the attribute is : {0}",
 myAttributes[ k ] );
         }
      }
   }
}
// The following example shows how the attributes related to the parameters
 
// of methods of the class can be retrieved at run time. A custom parameter
 
// level attribute named 'MyAttribute' is defined. This custom attribute
 is 
// associated with a parameter of the method 'MyMethod' of 'MyClass1'.
 This
// attribute is then retrieved at run time for the parameter of the
 method
// of the class 'MyClass1' and displayed.

import System.*;  
import System.Reflection.*;  
// Define a custom attribute with one named parameter.
/** @attribute AttributeUsage(AttributeTargets.Parameter)
 */
public class MyAttribute extends Attribute
{
    private String myName;

    public MyAttribute(String name)
    {
        myName = name;
    } //MyAttribute

    /** @property 
     */
    public String get_Name()
    {
        return myName;
    } //get_Name
} //MyAttribute

// Define a class which has a custom attribute associated with one of
 
// parameters of a method. 
public class MyClass1
{
    public void MyMethod(
        /** @attribute MyAttribute("This is an example parameter attribute")
         */
        int i)
    {
        return;
    } //MyMethod
} //MyClass1

public class MemberInfo_GetCustomAttributes
{
    public static void main(String[]
 args)
    {
        // Get the type of the class 'MyClass1'.
        Type myType = MyClass1.class.ToType();
        // Get the members associated with the class 'MyClass1'.
        MethodInfo myMethods[] = myType.GetMethods();
        // Display the attributes of type 'MyAttribute' for each 
        // of the parameters of each method of the class 'MyClass1'.
        for (int i = 0; i < myMethods.get_Length();
 i++) {
            // Get the parameters for the method.
            ParameterInfo myParameters[] = myMethods[i].GetParameters();
            Console.WriteLine("\nThe parameters for the method
 \"{0}\" "
                + "which have an custom attribute are : \n",
                myMethods.get_Item(i));
            for (int j = 0; j < myParameters.get_Length();
 j++) {
                // Get the attributes of type 'MyAttribute' for each
 parameter.
                Object myAttributes[] = myParameters[j].
                    GetCustomAttributes(MyAttribute.class.ToType(),
 false);
                if (myParameters[j].IsDefined(MyAttribute.class.ToType()
,
                    false)) {
                    Console.WriteLine("\nThe attributes for
 the parameter"
                        + " \"{0}\" are : \n", myParameters[j].
                        get_ParameterType());
                    // Display all the attributes of type 'MyAttribute'
 for 
                    // a parameter.
                    for (int k = 0; k <
 myAttributes.get_Length(); k++) {
                        Console.WriteLine("The type of the attribute is : {0}"
,
                            myAttributes.get_Item(k));
                    }
                }
            }
        }
    } //main
} //MemberInfo_GetCustomAttributes
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ParameterInfo.IsDefined メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ParameterInfo.IsDefined メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS