Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

 

C# LANGUAGE SPECIFICATION

1

public object P3 {

2

get {…}

3

set {…}

4}

5}

6[My(P1 = 1234, P3 = new int[]{1, 3, 5}, P2 = typeof(float))]

7class MyClass {}

8class C<T> {

9

[My(P2 = typeof(T))]

// Error – T not a closed type.

10

int x1;

 

11

[My(P2 = typeof(C<T>))]

// Error – C<T> not a closed type.

12

int x2;

 

13

[My(P2 = typeof(C<int>))]

// Ok

14

int x3;

 

15

[My(P2 = typeof(C<>))]

// Ok

16int x4;

17}

18end example]

19The attributes of a type declared in multiple parts are determined by combining, in an unspecified order, the

20attributes of each of its parts. If the same attribute is placed on multiple parts, it is equivalent to specifying

21that attribute multiple times on the type. [Example: The two parts:

22[Attr1, Attr2("hello")]

23partial class A {}

24[Attr3, Attr2("goodbye")]

25partial class A {}

26are equivalent to the following single declaration:

27[Attr1, Attr2("hello"), Attr3, Attr2("goodbye")]

28class A {}

29end example]

30Attributes on type parameters combine in the same way.

3124.3 Attribute instances

32An attribute instance is an instance that represents an attribute at run-time. An attribute is defined with an

33attribute class, positional arguments, and named arguments. An attribute instance is an instance of the

34attribute class that is initialized with the positional and named arguments.

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

36following subclauses.

3724.3.1 Compilation of an attribute

38The compilation of an attribute with attribute class T, positional-argument-list P and named-argument-list N,

39consists of the following steps:

40Follow the compile-time processing steps for compiling an object-creation-expression of the form

41new T(P). These steps either result in a compile-time error, or determine an instance constructor on T

42that can be invoked at run-time. Call this instance constructor C.

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

44For each named-argument Arg in N:

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

46o Name shall identify a non-static read-write public field or property on T. If T has no such field or

47property, then a compile-time error occurs.

372

Соседние файлы в предмете Электротехника