CallingConventions Enumeração
Definição
Define as convenções de chamada válidas para um método.Defines the valid calling conventions for a method.
Esta enumeração tem um atributo FlagsAttribute que permite uma combinação bit a bit dos valores membros dela.
public enum class CallingConventions
[System.Flags]
public enum CallingConventions
[System.Flags]
[System.Serializable]
public enum CallingConventions
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum CallingConventions
[<System.Flags>]
type CallingConventions =
[<System.Flags>]
[<System.Serializable>]
type CallingConventions =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CallingConventions =
Public Enum CallingConventions
- Herança
- Atributos
Campos
| Any | 3 | Especifica que a convenção de chamada |
| ExplicitThis | 64 | Especifica que a assinatura é uma assinatura de ponteiro de função, que representa uma chamada para um método virtual ou de instância (não um método estático).Specifies that the signature is a function-pointer signature, representing a call to an instance or virtual method (not a static method). Se |
| HasThis | 32 | Especifica um método virtual ou de instância (não um método estático).Specifies an instance or virtual method (not a static method). No tempo de execução, o método chamado é passado em um ponteiro para o objeto de destino como seu primeiro argumento (o ponteiro |
| Standard | 1 | Especifica a convenção de chamada padrão conforme determinado pelo Common Language Runtime.Specifies the default calling convention as determined by the common language runtime. Use esta convenção de chamada para métodos estáticos.Use this calling convention for static methods. Para métodos virtuais ou de instância, use |
| VarArgs | 2 | Especifica a convenção de chamada de métodos com argumentos variáveis.Specifies the calling convention for methods with variable arguments. |
Exemplos
using namespace System;
using namespace System::Reflection;
using namespace System::Security;
public ref class MyClass1
{
public:
MyClass1( int i ){}
};
int main()
{
try
{
Type^ myType = MyClass1::typeid;
array<Type^>^types = gcnew array<Type^>(1);
types[ 0 ] = int::typeid;
// Get the public instance constructor that takes an integer parameter.
ConstructorInfo^ constructorInfoObj = myType->GetConstructor( static_cast<BindingFlags>(BindingFlags::Instance | BindingFlags::Public), nullptr, CallingConventions::HasThis, types, nullptr );
if ( constructorInfoObj != nullptr )
{
Console::WriteLine( "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is: " );
Console::WriteLine( constructorInfoObj );
}
else
{
Console::WriteLine( "The constructor of MyClass1 that is a public instance method and takes an integer as a parameter is not available." );
}
}
catch ( ArgumentNullException^ e )
{
Console::WriteLine( "ArgumentNullException: {0}", e->Message );
}
catch ( ArgumentException^ e )
{
Console::WriteLine( "ArgumentException: {0}", e->Message );
}
catch ( SecurityException^ e )
{
Console::WriteLine( "SecurityException: {0}", e->Message );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
using System;
using System.Reflection;
using System.Security;
public class MyClass1
{
public MyClass1(int i){}
public static void Main()
{
try
{
Type myType = typeof(MyClass1);
Type[] types = new Type[1];
types[0] = typeof(int);
// Get the public instance constructor that takes an integer parameter.
ConstructorInfo constructorInfoObj = myType.GetConstructor(
BindingFlags.Instance | BindingFlags.Public, null,
CallingConventions.HasThis, types, null);
if(constructorInfoObj != null)
{
Console.WriteLine("The constructor of MyClass1 that is a public " +
"instance method and takes an integer as a parameter is: ");
Console.WriteLine(constructorInfoObj.ToString());
}
else
{
Console.WriteLine("The constructor of MyClass1 that is a public instance " +
"method and takes an integer as a parameter is not available.");
}
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: " + e.Message);
}
catch(ArgumentException e)
{
Console.WriteLine("ArgumentException: " + e.Message);
}
catch(SecurityException e)
{
Console.WriteLine("SecurityException: " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
}
Public Class MyClass1
Public Sub New(ByVal i As Integer)
End Sub
Public Shared Sub Main()
Try
Dim myType As Type = GetType(MyClass1)
Dim types(0) As Type
types(0) = GetType(Integer)
' Get the public instance constructor that takes an integer parameter.
Dim constructorInfoObj As ConstructorInfo = _
myType.GetConstructor(BindingFlags.Instance Or _
BindingFlags.Public, Nothing, _
CallingConventions.HasThis, types, Nothing)
If Not (constructorInfoObj Is Nothing) Then
Console.WriteLine("The constructor of MyClass1 that " + _
"is a public instance method and takes an " + _
"integer as a parameter is: ")
Console.WriteLine(constructorInfoObj.ToString())
Else
Console.WriteLine("The constructor MyClass1 that " + _
"is a public instance method and takes an " + _
"integer as a parameter is not available.")
End If
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: " + e.Message)
Catch e As ArgumentException
Console.WriteLine("ArgumentException: " + e.Message)
Catch e As SecurityException
Console.WriteLine("SecurityException: " + e.Message)
Catch e As Exception
Console.WriteLine("Exception: " + e.Message)
End Try
End Sub
End Class
Comentários
A Convenção de chamada nativa é o conjunto de regras que governam a ordem e o layout dos argumentos passados para os métodos compilados.The native calling convention is the set of rules governing the order and layout of arguments passed to compiled methods. Ele também controla como passar o valor de retorno, o que os registros devem usar para argumentos e se o método chamado ou de chamada remove argumentos da pilha.It also governs how to pass the return value, what registers to use for arguments, and whether the called or the calling method removes arguments from the stack.