13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATION[X]class Class1 {}[XAttribute]class Class2 {}[@X]class Class3 {}[@XAttribute]class Class4 {}// error: ambiguity// refers to XAttribute// refers to X// refers to XAttributeshows two attribute classes named X and XAttribute. The attribute [X] is ambiguous, since it could referto either X or XAttribute. Using a verbatim identifier allows the exact intent to be specified in such rarecases. The attribute [XAttribute] is not ambiguous (although it would be if there was an attribute classnamed XAttributeAttribute!). If the declaration for class X is removed, then both attributes refer to theattribute class named XAttribute, as follows:using System;[AttributeUsage(AttributeTargets.All)]public class XAttribute: Attribute{}[X]// refers to XAttributeclass Class1 {}[XAttribute] // refers to XAttributeclass Class2 {}[@X]// error: no attribute named “X”class Class3 {}end example]It is a compile-time error to use a single-use attribute class more than once on the same entity. [Example:The exampleusing System;[AttributeUsage(AttributeTargets.Class)]public class HelpStringAttribute: Attribute{string value;}public HelpStringAttribute(string value) {this.value = value;}public string Value { get {…} }[HelpString("Description of Class1")][HelpString("Another description of Class1")]public class Class1 {}results in a compile-time error because it attempts to use HelpString, which is a single-use attribute class,more than once on the declaration of Class1. end example]An expression E is an attribute-argument-expression if all of the following statements are true:• The type of E is an attribute parameter type (§24.1.3).• At compile-time, the value of E can be resolved to one of the following:A constant value.A System.Type object.A one-dimensional array of attribute-argument-expressions.[Example: For example:310

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!