|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
Attribute.GetCustomAttributes-Methode (ParameterInfo, Boolean)
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Parameter
- element
- Typ: System.Reflection.ParameterInfo
Ein Objekt, das von der ParameterInfo-Klasse abgeleitet wurde und einen Parameter eines Klassenmembers beschreibt.
- inherit
- Typ: System.Boolean
Wenn true, wird angegeben, dass auch die früheren Versionen von element hinsichtlich benutzerdefinierter Attribute durchsucht werden sollen.
Rückgabewert
Typ: System.Attribute[]| Ausnahme | Bedingung |
|---|---|
| ArgumentException | |
| ArgumentNullException | |
| TypeLoadException |
using System; using System.Reflection; using System.ComponentModel; namespace CustAttrs5CS { public class AClass { public void ParamArrayAndDesc( // Add ParamArray (with the keyword) and Description attributes. [Description("This argument is a ParamArray")] params int[] args) {} } class DemoClass { static void Main(string[] args) { // Get the Class type to access its metadata. Type clsType = typeof(AClass); // Get the type information for the method. MethodInfo mInfo = clsType.GetMethod("ParamArrayAndDesc"); if (mInfo != null) { // Get the parameter information. ParameterInfo[] pInfo = mInfo.GetParameters(); if (pInfo != null) { // Iterate through all the attributes for the parameter. foreach(Attribute attr in Attribute.GetCustomAttributes(pInfo[0])) { // Check for the ParamArray attribute. if (attr.GetType() == typeof(ParamArrayAttribute)) Console.WriteLine("Parameter {0} for method {1} " + "has the ParamArray attribute.", pInfo[0].Name, mInfo.Name); // Check for the Description attribute. else if (attr.GetType() == typeof(DescriptionAttribute)) { Console.WriteLine("Parameter {0} for method {1} " + "has a description attribute.", pInfo[0].Name, mInfo.Name); Console.WriteLine("The description is: \"{0}\"", ((DescriptionAttribute)attr).Description); } } } } } } } /* * Output: * Parameter args for method ParamArrayAndDesc has a description attribute. * The description is: "This argument is a ParamArray" * Parameter args for method ParamArrayAndDesc has the ParamArray attribute. */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.