Chyba kompilátoru CS1614
'name' je nejednoznačný mezi 'name' a 'nameAttribute'; použijte buď @name, nebo nameAttribute.
Kompilátor zjistil nejednoznačné specifikace atributu.
Kompilátor jazyka C# umožňuje pro usnadnění zadat ExampleAttribute jako pouze [Example]
. Nejednoznačnost však vzniká, pokud existuje třída atributu spolu Example
s ExampleAttribute, protože kompilátor nemůže zjistit, zda [Example]
odkazuje na Example
atribut nebo ExampleAttribute atribut. Pro objasnění použijte [@Example]
atribut Example
a [ExampleAttribute]
ExampleAttribute.
Následující ukázka vygeneruje 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() {
}
}
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro