AmbiguousMatchException Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da AmbiguousMatchException classe.
Sobrecargas
| Name | Description |
|---|---|
| AmbiguousMatchException() |
Inicializa uma nova instância da AmbiguousMatchException classe com uma string de mensagens vazia e a exceção de causa raiz definida como |
| AmbiguousMatchException(String) |
Inicializa uma nova instância da AmbiguousMatchException classe com a sua string de mensagens definida para a mensagem dada e a exceção de causa raiz definida para |
| AmbiguousMatchException(String, Exception) |
Inicializa uma nova instância da AmbiguousMatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção. |
AmbiguousMatchException()
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da AmbiguousMatchException classe com uma string de mensagens vazia e a exceção de causa raiz definida como null.
public:
AmbiguousMatchException();
public AmbiguousMatchException();
Public Sub New ()
Observações
AmbiguousMatchException herda de Exception. Este construtor define as propriedades do Exception objeto conforme mostrado na tabela seguinte.
| Property | Value |
|---|---|
| InnerException | null |
| Message | A corda vazia (""). |
Ver também
Aplica-se a
AmbiguousMatchException(String)
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da AmbiguousMatchException classe com a sua string de mensagens definida para a mensagem dada e a exceção de causa raiz definida para null.
public:
AmbiguousMatchException(System::String ^ message);
public AmbiguousMatchException(string message);
public AmbiguousMatchException(string? message);
new System.Reflection.AmbiguousMatchException : string -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String)
Parâmetros
- message
- String
Uma sequência a indicar a razão pela qual esta exceção foi lançada.
Observações
AmbiguousMatchException herda de Exception. Este construtor define as propriedades do Exception objeto conforme mostrado na tabela seguinte.
| Property | Value |
|---|---|
| InnerException | null |
| Message | O message fio. |
Aplica-se a
AmbiguousMatchException(String, Exception)
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da AmbiguousMatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção.
public:
AmbiguousMatchException(System::String ^ message, Exception ^ inner);
public AmbiguousMatchException(string message, Exception inner);
public AmbiguousMatchException(string? message, Exception? inner);
new System.Reflection.AmbiguousMatchException : string * Exception -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String, inner As Exception)
Parâmetros
- message
- String
A mensagem de erro que explica a razão da exceção.
- inner
- Exception
A exceção que é a causa da exceção atual. Se o inner parâmetro não nullfor , a exceção atual é elevada num catch bloco que gere a exceção interna.
Exemplos
O exemplo seguinte mostra dois métodos, cada um chamado Mymethod. Um método aceita um inteiro e o outro uma cadeia. Se um inteiro for passado para Mymethod, é utilizado o primeiro método. Se uma cadeia for passada, é usado o segundo método. Se não for possível determinar qual Mymethod usar, AmbiguousMatchException é lançado.
using System;
using System.Reflection;
namespace Ambiguity
{
class Myambiguous
{
//The first overload is typed to an int
public static void Mymethod(int number)
{
Console.WriteLine("I am from 'int' method");
}
//The second overload is typed to a string
public static void Mymethod(string alpha)
{
Console.WriteLine("I am from 'string' method.");
}
public static void Main()
{
try
{
//The following does not cause as exception
Mymethod(2); // goes to Mymethod(int)
Mymethod("3"); // goes to Mymethod(string)
Type Mytype = Type.GetType("Ambiguity.Myambiguous");
MethodInfo Mymethodinfo32 = Mytype.GetMethod("Mymethod", new Type[]{typeof(int)});
MethodInfo Mymethodinfostr = Mytype.GetMethod("Mymethod", new Type[]{typeof(System.String)});
//Invoke a method, utilizing a int integer
Mymethodinfo32.Invoke(null, new Object[]{2});
//Invoke the method utilizing a string
Mymethodinfostr.Invoke(null, new Object[]{"1"});
//The following line causes an ambiguious exception
MethodInfo Mymethodinfo = Mytype.GetMethod("Mymethod");
} // end of try block
catch (AmbiguousMatchException ex)
{
Console.WriteLine("\n{0}\n{1}", ex.GetType().FullName, ex.Message);
}
catch
{
Console.WriteLine("\nSome other exception.");
}
return;
}
}
}
//This code produces the following output:
//
// I am from 'int' method
// I am from 'string' method.
// I am from 'int' method
// I am from 'string' method.
// System.Reflection.AmbiguousMatchException
// Ambiguous match found.
Imports System.Reflection
Namespace Ambiguity
Class Myambiguous
'The first overload is typed to an Int32
Overloads Public Shared Sub Mymethod(number As Int32)
Console.WriteLine("I am from 'Int32' method")
End Sub
'The second overload is typed to a string
Overloads Public Shared Sub Mymethod(alpha As String)
Console.WriteLine("I am from 'string' method.")
End Sub
Public Shared Sub Main()
Try
'The following does not cause as exception
Mymethod(2) ' goes to Mymethod Int32)
Mymethod("3") ' goes to Mymethod(string)
Dim Mytype As Type = Type.GetType("Ambiguity.Myambiguous")
Dim Mymethodinfo32 As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(Int32)})
Dim Mymethodinfostr As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(System.String)})
'Invoke a method, utilizing a Int32 integer
Mymethodinfo32.Invoke(Nothing, New Object() {2})
'Invoke the method utilizing a string
Mymethodinfostr.Invoke(Nothing, New Object() {"1"})
'The following line causes an ambiguious exception
Dim Mymethodinfo As MethodInfo = Mytype.GetMethod("Mymethod")
' end of try block
Catch ex As AmbiguousMatchException
Console.WriteLine(Environment.NewLine + "{0}" + Environment.NewLine + "{1}", ex.GetType().FullName, ex.Message)
Catch
Console.WriteLine(Environment.NewLine + "Some other exception.")
End Try
Return
End Sub
End Class
End Namespace
' This code produces the following output:
'
' I am from 'Int32' method
' I am from 'string' method.
' I am from 'Int32' method
' I am from 'string' method.
'
' System.Reflection.AmbiguousMatchException
' Ambiguous match found.
Observações
Uma exceção lançada como resultado direto de uma exceção anterior deve incluir uma referência à exceção anterior na InnerException propriedade. A InnerException propriedade devolve o mesmo valor que é passado ao construtor, ou null se a InnerException propriedade não fornecer o valor de exceção interna ao construtor.
A tabela seguinte mostra os valores iniciais das propriedades para uma instância de AmbiguousMatchException.
| Property | Value |
|---|---|
| InnerException | A referência à exceção interna. |
| Message | A cadeia de mensagens de erro. |