Attribut-argument muss ein konstanter Ausdruck sein

Könnte mir jemand bitte erklären, warum das folgende interface-definition läßt sich mit dem Fehler in Visual Studio 2010?

   [IncompleteCodePort(SourceOriginType.Other, "This should be a GL abstraction depending on what OpenGL API will be used")]
    public interface IGL
    {
        ///<summary>
        ///Returns true if provided function is available or supported by graphics API
        ///</summary>
        ///<param name="funcName"></param>
        ///<returns></returns>
        bool IsFunctionAvailable(string funcName);

        ///<summary>
        ///Returns true if provided function is supported as extension by graphics API
        ///</summary>
        ///<param name="funcName"></param>
        ///<returns></returns>
        bool IsExtensionAvailable(string funcName);
    }



public class IncompleteCodePortAttribute : Attribute
    {
        public SourceOriginType SourceOriginType { get; private set; }
        public string SourceUrl { get; private set; }
        public string Reason { get; private set; }


        public IncompleteCodePortAttribute(SourceOriginType originType, string reason, string sourceUrl = null)
        {
            SourceOriginType = originType;
            SourceUrl = sourceUrl;
            Reason = reason;
        }
    }

    public enum SourceOriginType
    {
        CodePlex,
        WorldWindJdk,
        StackOverflow,
        Other
    }

and error bin ich immer:

Attribut-argument muss ein konstanter Ausdruck sein, typeof-Ausdruck oder ein array creation expression eines Attributs parameter Typ

Wenn ich entfernen Sie das benutzerdefinierte-Attribut, bekomme ich keine Fehler bei der Kompilierung.

  • Was ist IncompleteCodePort? Post alle seine Konstrukteure.
  • Ich war in der Lage zu kompilieren, die mit einem dummy-IncompleteCodePort Klasse. Ich glaube, du bist fehlen einige Informationen hier.
  • Wenn Sie mit Enum im IncompleteCodePort Klasse, nicht. Verwenden SourceOriginType statt.
  • Mein schlechtes. Geschrieben, das viel zu spät. Ich habe die IncompleteCodePortAttribute definition.
  • Ich nehme, was ich gesagt habe zurück, es scheint der code eigentlich gar nicht kompilieren einwandfrei unter VS2010 (aber das tut es unter VS2012).
  • Es ist ein Fehler in der c# - compiler. Es wurde behoben. Siehe stackoverflow.com/questions/8290853/...

InformationsquelleAutor Klaus Nji | 2013-02-24
Schreibe einen Kommentar