X hits on this document

1295 views

0 shares

0 downloads

0 comments

321 / 396

C# LANGUAGE SPECIFICATION

The type of E is an attribute parameter type (§‎17.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.

For example:

using System;

[AttributeUsage(AttributeTargets.Class)] public class TestAttribute: Attribute { public int P1 { get {...} set {...} }

public Type P2 { get {...} set {...} }

public object P3 { get {...} set {...} } }

[Test(P1 = 1234, P3 = new int[] {1, 3, 5}, P2 = typeof(float))] class MyClass {}

17.3 Attribute instances

An attribute instance is an instance that represents an attribute at run-time. An attribute is defined with an attribute class, positional arguments, and named arguments. An attribute instance is an instance of the attribute class that is initialized with the positional and named arguments.

Retrieval of an attribute instance involves both compile-time and run-time processing, as described in the following sections.

17.3.1 Compilation of an attribute

The compilation of an attribute with attribute class T, positional-argument-list P and named-argument-list N, consists of the following steps:

Follow the compile-time processing steps for compiling an object-creation-expression of the form new T(P). These steps either result in a compile-time error, or determine an instance constructor C on T that can be invoked at run-time.

If C does not have public accessibility, then a compile-time error occurs.

For each named-argument Arg in N:

Let Name be the identifier of the named-argument Arg.

Name must identify a non-static read-write public field or property on T. If T has no such field or property, then a compile-time error occurs.

308Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1295
Page views1295
Page last viewedSat Jan 21 05:03:58 UTC 2017
Pages396
Paragraphs9401
Words133190

Comments