Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Aggiornamento: novembre 2007
Messaggio di errore
'nome' è ambiguo tra 'attributo1' e 'attributo2'; utilizzare '@attributo' o 'attributoAttribute'
'name' is ambiguous; between 'attribute1' and 'attribute2'. use either '@attribute' or 'attributeAttribute'
È stata rilevata una specifica di attributo ambigua.
Per comodità, nel compilatore C# è possibile specificare ExampleAttribute come [Example]. L'ambiguità tuttavia si verifica se oltre a ExampleAttribute esiste anche una classe Attribute chiamata Example, in quanto il compilatore non è in grado di riconoscere se [Example] fa riferimento all'attributo Example o all'attributo ExampleAttribute. Per maggiore chiarezza, utilizzare [@Example] per l'attributo Example e [ExampleAttribute] per ExampleAttribute.
Il seguente codice di esempio genera l'errore CS1614:
// CS1614.cs
using System;
// Both of the following classes are valid attributes with valid
// names (MySpecial and MySpecialAttribute). However, because the lookup
// rules for attributes involves auto-appending the 'Attribute' suffix
// to the identifier, these two attributes become ambiguous; that is,
// if you specify MySpecial, the compiler can't tell if you want
// MySpecial or MySpecialAttribute.
public class MySpecial : Attribute {
public MySpecial() {}
}
public class MySpecialAttribute : Attribute {
public MySpecialAttribute() {}
}
class MakeAWarning {
[MySpecial()] // CS1614
// Ambiguous: MySpecial or MySpecialAttribute?
public static void Main() {
}
[@MySpecial()] // This isn't ambiguous, it binds to the first attribute above.
public static void NoWarning() {
}
[MySpecialAttribute()] // This isn't ambiguous, it binds to the second attribute above.
public static void NoWarning2() {
}
[@MySpecialAttribute()] // This is also legal.
public static void NoWarning3() {
}
}