Attribute.IsDefined Yöntem

Tanım

Belirtilen türe ait özel özniteliklerin bir derlemeye, modüle, tür üyesine veya yöntem parametresine uygulanıp uygulanmadığını belirler.

Aşırı Yüklemeler

IsDefined(ParameterInfo, Type, Boolean)

Herhangi bir özel özniteliğin bir yöntem parametresine uygulanıp uygulanmadığını belirler. Parametreler yöntem parametresini, aranacak özel özniteliğin türünü ve yöntem parametresinin alt öğelerinde arama yapılıp yapılmayacağını belirtir.

IsDefined(Module, Type, Boolean)

Herhangi bir özel özniteliğin bir modüle uygulanıp uygulanmadığını belirler. Parametreler modülü, aranacak özel özniteliğin türünü ve yoksayılan arama seçeneğini belirtir.

IsDefined(MemberInfo, Type, Boolean)

Herhangi bir özel özniteliğin bir türün üyesine uygulanıp uygulanmadığını belirler. Parametreler üyeyi, aranacak özel özniteliğin türünü ve üyenin alt öğelerinde arama yapılıp yapılmayacağını belirtir.

IsDefined(Assembly, Type, Boolean)

Herhangi bir özel özniteliğin bir derlemeye uygulanıp uygulanmadığını belirler. Parametreler derlemeyi, aranacak özel özniteliğin türünü ve yoksayılan arama seçeneğini belirtir.

IsDefined(MemberInfo, Type)

Herhangi bir özel özniteliğin bir türün üyesine uygulanıp uygulanmadığını belirler. Parametreler, üyeyi ve aranacak özel özniteliğin türünü belirtir.

IsDefined(Module, Type)

Belirtilen türe ait özel özniteliklerin bir modüle uygulanıp uygulanmadığını belirler. Parametreler modülü ve aranacak özel özniteliğin türünü belirtir.

IsDefined(Assembly, Type)

Herhangi bir özel özniteliğin bir derlemeye uygulanıp uygulanmadığını belirler. Parametreler derlemeyi ve aranacak özel özniteliğin türünü belirtir.

IsDefined(ParameterInfo, Type)

Herhangi bir özel özniteliğin bir yöntem parametresine uygulanıp uygulanmadığını belirler. Parametreler yöntem parametresini ve aranacak özel özniteliğin türünü belirtir.

IsDefined(ParameterInfo, Type, Boolean)

Herhangi bir özel özniteliğin bir yöntem parametresine uygulanıp uygulanmadığını belirler. Parametreler yöntem parametresini, aranacak özel özniteliğin türünü ve yöntem parametresinin alt öğelerinde arama yapılıp yapılmayacağını belirtir.

C#
public static bool IsDefined (System.Reflection.ParameterInfo element, Type attributeType, bool inherit);

Parametreler

element
ParameterInfo

Sınıfın bir üyesinin ParameterInfo parametresini açıklayan sınıfından türetilmiş bir nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

inherit
Boolean

ise true, öğesinin atalarını element özel öznitelikler için de aramayı belirtir.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

element bir yöntem, oluşturucu veya tür değildir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak ParameterInfo kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

namespace IsDef5CS
{
    public class TestClass
    {
        // Assign a ParamArray attribute to the parameter using the keyword.
        public void Method1(params String[] args)
        {}
    }

    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(TestClass);
            // Get the MethodInfo object for Method1.
            MethodInfo mInfo = clsType.GetMethod("Method1");
            // Get the ParameterInfo array for the method parameters.
            ParameterInfo[] pInfo = mInfo.GetParameters();
            if (pInfo != null)
            {
                // See if the ParamArray attribute is defined.
                bool isDef = Attribute.IsDefined(pInfo[0],
                                                 typeof(ParamArrayAttribute));
                // Display the result.
                Console.WriteLine("The ParamArray attribute {0} defined for " +
                                  "parameter {1} of method {2}.",
                                  isDef ? "is" : "is not",
                                  pInfo[0].Name,
                                  mInfo.Name);
            }
            else
                Console.WriteLine("The parameters information could " +
                            "not be retrieved for method {0}.", mInfo.Name);
        }
    }
}

/*
 * Output:
 * The ParamArray attribute is defined for parameter args of method Method1.
 */

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(Module, Type, Boolean)

Herhangi bir özel özniteliğin bir modüle uygulanıp uygulanmadığını belirler. Parametreler modülü, aranacak özel özniteliğin türünü ve yoksayılan arama seçeneğini belirtir.

C#
public static bool IsDefined (System.Reflection.Module element, Type attributeType, bool inherit);

Parametreler

element
Module

Sınıfından Module türetilen ve taşınabilir yürütülebilir dosyayı açıklayan nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

inherit
Boolean

Bu parametre yoksayılır ve bu yöntemin çalışmasını etkilemez.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak Module kullanımını IsDefinedgösterir.

C#
using System;
using System.Diagnostics;

// Add the Debuggable attribute to the module.
[module:Debuggable(true, false)]
namespace IsDef2CS
{
    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(DemoClass);
            // See if the Debuggable attribute is defined for this module.
            bool isDef = Attribute.IsDefined(clsType.Module,
                typeof(DebuggableAttribute));
            // Display the result.
            Console.WriteLine("The Debuggable attribute {0} " +
                "defined for Module {1}.",
                isDef ? "is" : "is not",
                clsType.Module.Name);
            // If the attribute is defined, display the JIT settings.
            if (isDef)
            {
                // Retrieve the attribute itself.
                DebuggableAttribute dbgAttr = (DebuggableAttribute)
                    Attribute.GetCustomAttribute(clsType.Module,
                    typeof(DebuggableAttribute));
                if (dbgAttr != null)
                {
                    Console.WriteLine("JITTrackingEnabled is {0}.",
                        dbgAttr.IsJITTrackingEnabled);
                    Console.WriteLine("JITOptimizerDisabled is {0}.",
                        dbgAttr.IsJITOptimizerDisabled);
                }
                else
                    Console.WriteLine("The Debuggable attribute " +
                        "could not be retrieved.");
            }
        }
    }
}

/*
 * Output:
 * The Debuggable attribute is defined for Module IsDef2CS.exe.
 * JITTrackingEnabled is True.
 * JITOptimizerDisabled is False.
 */

Açıklamalar

Bu yöntem parametresini inherit yoksayar ve özel öznitelikler için öğesinin atalarını element aramaz.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(MemberInfo, Type, Boolean)

Herhangi bir özel özniteliğin bir türün üyesine uygulanıp uygulanmadığını belirler. Parametreler üyeyi, aranacak özel özniteliğin türünü ve üyenin alt öğelerinde arama yapılıp yapılmayacağını belirtir.

C#
public static bool IsDefined (System.Reflection.MemberInfo element, Type attributeType, bool inherit);

Parametreler

element
MemberInfo

Bir sınıfın MemberInfo oluşturucu, olay, alan, yöntem, tür veya özellik üyesini tanımlayan sınıfından türetilen nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

inherit
Boolean

ise true, öğesinin atalarını element özel öznitelikler için de aramayı belirtir.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

element oluşturucu, yöntem, özellik, olay, tür veya alan değildir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak MemberInfo kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

namespace IsDef4CS
{
    public class TestClass
    {
        // Assign the Obsolete attribute to a method.
        [Obsolete("This method is obsolete. Use Method2 instead.")]
        public void Method1()
        {}
        public void Method2()
        {}
    }

    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(TestClass);
            // Get the MethodInfo object for Method1.
            MethodInfo mInfo = clsType.GetMethod("Method1");
            // See if the Obsolete attribute is defined for this method.
            bool isDef = Attribute.IsDefined(mInfo, typeof(ObsoleteAttribute));
            // Display the result.
            Console.WriteLine("The Obsolete Attribute {0} defined for {1} of class {2}.",
                isDef ? "is" : "is not", mInfo.Name, clsType.Name);
            // If it's defined, display the attribute's message.
            if (isDef)
            {
                ObsoleteAttribute obsAttr =
                                 (ObsoleteAttribute)Attribute.GetCustomAttribute(
                                                    mInfo, typeof(ObsoleteAttribute));
                if (obsAttr != null)
                    Console.WriteLine("The message is: \"{0}\".",
                        obsAttr.Message);
                else
                    Console.WriteLine("The message could not be retrieved.");
            }
        }
    }
}

/*
 * Output:
 * The Obsolete Attribute is defined for Method1 of class TestClass.
 * The message is: "This method is obsolete. Use Method2 instead.".
 */

Açıklamalar

Not

.NET Framework sürüm 2.0'dan başlayarak, bir türün, yöntemin veya oluşturucunun yeni meta veri biçiminde depolanan güvenlik öznitelikleri varsa bu yöntem döndürürtrue. Sürüm 2.0 veya üzeri ile derlenen derlemeler yeni biçimi kullanır. .NET Framework önceki sürümleriyle derlenen dinamik derlemeler ve derlemeler eski XML biçimini kullanır. Bkz. Bildirim Temelli Güvenlik Özniteliklerini Yayma.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(Assembly, Type, Boolean)

Herhangi bir özel özniteliğin bir derlemeye uygulanıp uygulanmadığını belirler. Parametreler derlemeyi, aranacak özel özniteliğin türünü ve yoksayılan arama seçeneğini belirtir.

C#
public static bool IsDefined (System.Reflection.Assembly element, Type attributeType, bool inherit);

Parametreler

element
Assembly

Sınıfından Assembly türetilen ve yeniden kullanılabilir modül koleksiyonunu açıklayan bir nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

inherit
Boolean

Bu parametre yoksayılır ve bu yöntemin çalışmasını etkilemez.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak Assembly kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

// Add an AssemblyDescription attribute
[assembly: AssemblyDescription("A sample description")]
namespace IsDef1CS
{
    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(DemoClass);
            // Get the assembly object.
            Assembly assy = clsType.Assembly;
            // Store the assembly's name.
            String assyName = assy.GetName().Name;
            // See if the Assembly Description is defined.
            bool isdef = Attribute.IsDefined(assy,
                typeof(AssemblyDescriptionAttribute));
            if (isdef)
            {
                // Affirm that the attribute is defined.
                Console.WriteLine("The AssemblyDescription attribute " +
                    "is defined for assembly {0}.", assyName);
                // Get the description attribute itself.
                AssemblyDescriptionAttribute adAttr =
                    (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
                    assy, typeof(AssemblyDescriptionAttribute));
                // Display the description.
                if (adAttr != null)
                    Console.WriteLine("The description is \"{0}\".",
                        adAttr.Description);
                else
                    Console.WriteLine("The description could not " +
                        "be retrieved.");
            }
            else
                Console.WriteLine("The AssemblyDescription attribute is not " +
                    "defined for assembly {0}.", assyName);
        }
    }
}

/*
 * Output:
 * The AssemblyDescription attribute is defined for assembly IsDef1CS.
 * The description is "A sample description".
 */

Açıklamalar

Not

.NET Framework sürüm 2.0'dan başlayarak, derlemenin yeni meta veri biçiminde depolanan güvenlik öznitelikleri varsa bu yöntem döndürürtrue. Sürüm 2.0 veya üzeri ile derlenen derlemeler yeni biçimi kullanır. .NET Framework önceki sürümleriyle derlenen dinamik derlemeler ve derlemeler eski XML biçimini kullanır. Bkz. Bildirim Temelli Güvenlik Özniteliklerini Yayma.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(MemberInfo, Type)

Herhangi bir özel özniteliğin bir türün üyesine uygulanıp uygulanmadığını belirler. Parametreler, üyeyi ve aranacak özel özniteliğin türünü belirtir.

C#
public static bool IsDefined (System.Reflection.MemberInfo element, Type attributeType);

Parametreler

element
MemberInfo

Bir sınıfın MemberInfo oluşturucu, olay, alan, yöntem, tür veya özellik üyesini tanımlayan sınıfından türetilen nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

element oluşturucu, yöntem, özellik, olay, tür veya alan değildir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak MemberInfo kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

namespace IsDef4CS
{
    public class TestClass
    {
        // Assign the Obsolete attribute to a method.
        [Obsolete("This method is obsolete. Use Method2 instead.")]
        public void Method1()
        {}
        public void Method2()
        {}
    }

    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(TestClass);
            // Get the MethodInfo object for Method1.
            MethodInfo mInfo = clsType.GetMethod("Method1");
            // See if the Obsolete attribute is defined for this method.
            bool isDef = Attribute.IsDefined(mInfo, typeof(ObsoleteAttribute));
            // Display the result.
            Console.WriteLine("The Obsolete Attribute {0} defined for {1} of class {2}.",
                isDef ? "is" : "is not", mInfo.Name, clsType.Name);
            // If it's defined, display the attribute's message.
            if (isDef)
            {
                ObsoleteAttribute obsAttr =
                                 (ObsoleteAttribute)Attribute.GetCustomAttribute(
                                                    mInfo, typeof(ObsoleteAttribute));
                if (obsAttr != null)
                    Console.WriteLine("The message is: \"{0}\".",
                        obsAttr.Message);
                else
                    Console.WriteLine("The message could not be retrieved.");
            }
        }
    }
}

/*
 * Output:
 * The Obsolete Attribute is defined for Method1 of class TestClass.
 * The message is: "This method is obsolete. Use Method2 instead.".
 */

Açıklamalar

öğesinin element ataları özel öznitelikler için aranıyor.

Not

.NET Framework sürüm 2.0'dan başlayarak, bir türün, yöntemin veya oluşturucunun yeni meta veri biçiminde depolanan güvenlik öznitelikleri varsa bu yöntem döndürürtrue. Sürüm 2.0 veya üzeri ile derlenen derlemeler yeni biçimi kullanır. .NET Framework önceki sürümleriyle derlenen dinamik derlemeler ve derlemeler eski XML biçimini kullanır. Bkz. Bildirim Temelli Güvenlik Özniteliklerini Yayma.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(Module, Type)

Belirtilen türe ait özel özniteliklerin bir modüle uygulanıp uygulanmadığını belirler. Parametreler modülü ve aranacak özel özniteliğin türünü belirtir.

C#
public static bool IsDefined (System.Reflection.Module element, Type attributeType);

Parametreler

element
Module

Sınıfından Module türetilen ve taşınabilir yürütülebilir dosyayı açıklayan nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak Module kullanımını IsDefinedgösterir.

C#
using System;
using System.Diagnostics;

// Add the Debuggable attribute to the module.
[module:Debuggable(true, false)]
namespace IsDef2CS
{
    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(DemoClass);
            // See if the Debuggable attribute is defined for this module.
            bool isDef = Attribute.IsDefined(clsType.Module,
                typeof(DebuggableAttribute));
            // Display the result.
            Console.WriteLine("The Debuggable attribute {0} " +
                "defined for Module {1}.",
                isDef ? "is" : "is not",
                clsType.Module.Name);
            // If the attribute is defined, display the JIT settings.
            if (isDef)
            {
                // Retrieve the attribute itself.
                DebuggableAttribute dbgAttr = (DebuggableAttribute)
                    Attribute.GetCustomAttribute(clsType.Module,
                    typeof(DebuggableAttribute));
                if (dbgAttr != null)
                {
                    Console.WriteLine("JITTrackingEnabled is {0}.",
                        dbgAttr.IsJITTrackingEnabled);
                    Console.WriteLine("JITOptimizerDisabled is {0}.",
                        dbgAttr.IsJITOptimizerDisabled);
                }
                else
                    Console.WriteLine("The Debuggable attribute " +
                        "could not be retrieved.");
            }
        }
    }
}

/*
 * Output:
 * The Debuggable attribute is defined for Module IsDef2CS.exe.
 * JITTrackingEnabled is True.
 * JITOptimizerDisabled is False.
 */

Açıklamalar

öğesinin element ataları özel öznitelikler için aranmıyor.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(Assembly, Type)

Herhangi bir özel özniteliğin bir derlemeye uygulanıp uygulanmadığını belirler. Parametreler derlemeyi ve aranacak özel özniteliğin türünü belirtir.

C#
public static bool IsDefined (System.Reflection.Assembly element, Type attributeType);

Parametreler

element
Assembly

Sınıfından Assembly türetilen ve yeniden kullanılabilir modül koleksiyonunu açıklayan bir nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak Assembly kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

// Add an AssemblyDescription attribute
[assembly: AssemblyDescription("A sample description")]
namespace IsDef1CS
{
    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(DemoClass);
            // Get the assembly object.
            Assembly assy = clsType.Assembly;
            // Store the assembly's name.
            String assyName = assy.GetName().Name;
            // See if the Assembly Description is defined.
            bool isdef = Attribute.IsDefined(assy,
                typeof(AssemblyDescriptionAttribute));
            if (isdef)
            {
                // Affirm that the attribute is defined.
                Console.WriteLine("The AssemblyDescription attribute " +
                    "is defined for assembly {0}.", assyName);
                // Get the description attribute itself.
                AssemblyDescriptionAttribute adAttr =
                    (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
                    assy, typeof(AssemblyDescriptionAttribute));
                // Display the description.
                if (adAttr != null)
                    Console.WriteLine("The description is \"{0}\".",
                        adAttr.Description);
                else
                    Console.WriteLine("The description could not " +
                        "be retrieved.");
            }
            else
                Console.WriteLine("The AssemblyDescription attribute is not " +
                    "defined for assembly {0}.", assyName);
        }
    }
}

/*
 * Output:
 * The AssemblyDescription attribute is defined for assembly IsDef1CS.
 * The description is "A sample description".
 */

Açıklamalar

Not

.NET Framework sürüm 2.0'dan başlayarak, derlemenin yeni meta veri biçiminde depolanan güvenlik öznitelikleri varsa bu yöntem döndürürtrue. Sürüm 2.0 veya üzeri ile derlenen derlemeler yeni biçimi kullanır. .NET Framework önceki sürümleriyle derlenen dinamik derlemeler ve derlemeler eski XML biçimini kullanır. Bkz. Bildirim Temelli Güvenlik Özniteliklerini Yayma.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

IsDefined(ParameterInfo, Type)

Herhangi bir özel özniteliğin bir yöntem parametresine uygulanıp uygulanmadığını belirler. Parametreler yöntem parametresini ve aranacak özel özniteliğin türünü belirtir.

C#
public static bool IsDefined (System.Reflection.ParameterInfo element, Type attributeType);

Parametreler

element
ParameterInfo

Sınıfın bir üyesinin ParameterInfo parametresini açıklayan sınıfından türetilmiş bir nesne.

attributeType
Type

Aranacak özel özniteliğin türü veya temel türü.

Döndürülenler

Boolean

true türüne attributeType özel bir öznitelik uygulanırsa; uygulanmazsa element, false.

Özel durumlar

element veya attributeType şeklindedir null.

attributeType , 'den Attributetüretilmemiştir.

Örnekler

Aşağıdaki kod örneği, parametresini alarak ParameterInfo kullanımını IsDefinedgösterir.

C#
using System;
using System.Reflection;

namespace IsDef5CS
{
    public class TestClass
    {
        // Assign a ParamArray attribute to the parameter using the keyword.
        public void Method1(params String[] args)
        {}
    }

    public class DemoClass
    {
        static void Main(string[] args)
        {
            // Get the class type to access its metadata.
            Type clsType = typeof(TestClass);
            // Get the MethodInfo object for Method1.
            MethodInfo mInfo = clsType.GetMethod("Method1");
            // Get the ParameterInfo array for the method parameters.
            ParameterInfo[] pInfo = mInfo.GetParameters();
            if (pInfo != null)
            {
                // See if the ParamArray attribute is defined.
                bool isDef = Attribute.IsDefined(pInfo[0],
                                                 typeof(ParamArrayAttribute));
                // Display the result.
                Console.WriteLine("The ParamArray attribute {0} defined for " +
                                  "parameter {1} of method {2}.",
                                  isDef ? "is" : "is not",
                                  pInfo[0].Name,
                                  mInfo.Name);
            }
            else
                Console.WriteLine("The parameters information could " +
                            "not be retrieved for method {0}.", mInfo.Name);
        }
    }
}

/*
 * Output:
 * The ParamArray attribute is defined for parameter args of method Method1.
 */

Açıklamalar

öğesinin element ataları özel öznitelikler için aranıyor.

Şunlara uygulanır

.NET 7 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1