ParameterAttributes Výčet
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Definuje atributy, které lze přidružit k parametru. Ty jsou definovány v CorHdr.h.
Tento výčet podporuje bitové kombinace hodnot jeho členů.
public enum class ParameterAttributes
[System.Flags]
public enum ParameterAttributes
[System.Flags]
[System.Serializable]
public enum ParameterAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ParameterAttributes
[<System.Flags>]
type ParameterAttributes =
[<System.Flags>]
[<System.Serializable>]
type ParameterAttributes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ParameterAttributes =
Public Enum ParameterAttributes
- Dědičnost
- Atributy
Pole
| Name | Hodnota | Description |
|---|---|---|
| None | 0 | Určuje, že neexistuje žádný atribut parametru. |
| In | 1 | Určuje, že parametr je vstupním parametrem. |
| Out | 2 | Určuje, že parametr je výstupní parametr. |
| Lcid | 4 | Určuje, že parametr je identifikátor národního prostředí (lcid). |
| Retval | 8 | Určuje, že parametr je návratová hodnota. |
| Optional | 16 | Určuje, že parametr je volitelný. |
| HasDefault | 4096 | Určuje, že parametr má výchozí hodnotu. |
| HasFieldMarshal | 8192 | Určuje, že parametr obsahuje informace o zařazování polí. |
| Reserved3 | 16384 | Rezervovaný. |
| Reserved4 | 32768 | Rezervovaný. |
| ReservedMask | 61440 | Určuje, že parametr je vyhrazený. |
Příklady
Následující příklad zobrazí atributy zadaného parametru.
using System;
using System.Reflection;
class paramatt
{
public static void mymethod (string str1, out string str2, ref string str3)
{
str2 = "string";
}
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.ParameterAttributes");
// Get the Type and the method.
Type Mytype = Type.GetType("paramatt");
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
// Display the method.
Console.Write("\nMymethodbase = " + Mymethodbase);
// Get the ParameterInfo array.
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
// Get and display the attributes for the second parameter.
ParameterAttributes Myparamattributes = Myarray[1].Attributes;
Console.Write("\nFor the second parameter:\nMyparamattributes = "
+ (int) Myparamattributes
+ ", which is an "
+ Myparamattributes.ToString());
return 0;
}
}
Imports System.Reflection
Class paramatt
Public Shared Sub mymethod(ByVal str1 As String, ByRef str2 As String, _
ByRef str3 As String)
str2 = "string"
End Sub
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf + "Reflection.ParameterAttributes")
' Get the Type and the method.
Dim Mytype As Type = Type.GetType("paramatt")
Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")
' Display the method.
Console.WriteLine("Mymethodbase = " + Mymethodbase.ToString())
' Get the ParameterInfo array.
Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()
' Get and display the attributes for the second parameter.
Dim Myparamattributes As ParameterAttributes = Myarray(1).Attributes
Console.WriteLine("For the second parameter:" + ControlChars.CrLf _
+ "Myparamattributes = " + CInt(Myparamattributes).ToString() _
+ ", which is a " + Myparamattributes.ToString())
Return 0
End Function
End Class
Poznámky
Pokud chcete získat ParameterAttributes hodnotu, nejprve získejte Typehodnotu . Z pole Typezískejte ParameterInfo pole. Hodnota ParameterAttributes je v poli.
Tyto hodnoty enumerátoru jsou závislé na volitelných metadatech. Ne všechny atributy jsou k dispozici ve všech kompilátorech. Podle příslušných pokynů kompilátoru určete, které výčtové hodnoty jsou k dispozici.