ParameterAttributes Enumeration
Defines the attributes that can be associated with a parameter. These are defined in CorHdr.h.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
[Visual Basic] <Flags> <Serializable> Public Enum ParameterAttributes [C#] [Flags] [Serializable] public enum ParameterAttributes [C++] [Flags] [Serializable] __value public enum ParameterAttributes [JScript] public Flags Serializable enum ParameterAttributes
Remarks
To get the ParameterAttributes value, first get the Type. From the Type, get the ParameterInfo array. The ParameterAttributes value is within the array.
These enumerator values are dependent on optional metadata. Not all attributes are available from all compilers. See the appropriate compiler instructions to determine which enumerated values are available.
Members
| Member name | Description | Value |
|---|---|---|
| HasDefault Supported by the .NET Compact Framework. | Specifies that the parameter has a default value. | 4096 |
| HasFieldMarshal Supported by the .NET Compact Framework. | Specifies that the parameter has field marshaling information. | 8192 |
| In Supported by the .NET Compact Framework. | Specifies that the parameter is an input parameter. | 1 |
| Lcid Supported by the .NET Compact Framework. | Specifies that the parameter is a locale identifier (lcid). | 4 |
| None Supported by the .NET Compact Framework. | Specifies that there is no parameter attribute. | 0 |
| Optional Supported by the .NET Compact Framework. | Specifies that the parameter is optional. | 16 |
| Out Supported by the .NET Compact Framework. | Specifies that the parameter is an output parameter. | 2 |
| Reserved3 Supported by the .NET Compact Framework. | Reserved. | 16384 |
| Reserved4 Supported by the .NET Compact Framework. | Reserved. | 32768 |
| ReservedMask Supported by the .NET Compact Framework. | Specifies that the parameter is reserved. | 61440 |
| Retval Supported by the .NET Compact Framework. | Specifies that the parameter is a return value. | 8 |
Example
[Visual Basic, C#, C++] The following example displays the attributes of the specified parameter.
[Visual Basic] Imports System Imports System.Reflection Imports Microsoft.VisualBasic 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 [C#] 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; } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Reflection; using namespace System::Runtime::InteropServices; public __gc class paramatt { public: static void mymethod (String* str1, [Out] String** str2, String** str3) { *str2 = S"string"; } }; int main() { Console::WriteLine(S"\nReflection.ParameterAttributes"); // Get the Type and the method. Type* Mytype = Type::GetType(S"paramatt"); MethodBase* Mymethodbase = Mytype->GetMethod(S"mymethod"); // Display the method. Console::Write(S"\nMymethodbase = {0}", 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(S"\nFor the second parameter:\nMyparamattributes = {0}, which is an {1}", __box((int)Myparamattributes), __box(Myparamattributes)); return 0; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Reflection
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)