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

C# LANGUAGE SPECIFICATION

1A declaration of a new member hides an inherited member only within the scope of the new member.

2[Example:

3class Base

4{

5public static void F() {}

6}

7class Derived: Base

8{

9

new private static void F() {} // Hides Base.F in Derived only

10}

11class MoreDerived: Derived

12{

13

static void G() { F(); }

// Invokes Base.F

14}

15In the example above, the declaration of F in Derived hides the F that was inherited from Base, but since

16the new F in Derived has private access, its scope does not extend to MoreDerived. Thus, the call F() in

17MoreDerived.G is valid and will invoke Base.F. end example]

1810.8 Namespace and type names

19Several contexts in a C# program require a namespace-name or a type-name to be specified.

20namespace-name:

21

namespace-or-type-name

22

type-name:

23

namespace-or-type-name

24

namespace-or-type-name:

25

identifier type-argument-listopt

26

qualified-alias-member

27

namespace-or-type-name . identifier type-argument-listop

28A namespace-name is a namespace-or-type-name that refers to a namespace.

29Following resolution as described below, the namespace-or-type-name of a namespace-name shall refer to a

30namespace, or otherwise a compile-time error occurs. Type arguments (§26.5.1) shall not be present in a

31namespace-name (only types can have type arguments).

32A type-name is a namespace-or-type-name that refers to a type. Following resolution as described below, the

33namespace-or-type-name of a type-name shall refer to a type, or otherwise a compile-time error occurs.

34The syntax and semantics of qualified-alias-member are defined in §16.7.

35A namespace-or-type-name that is not a qualified-alias-member has one of four forms:

36I

37I<A1, ..., AK>

38N.I

39• N.I<A1, ..., AK>

40where I is a single identifier, N is a namespace-or-type-name and <A1, ..., AK> is an optional type-

41argument-list. When no type-argument-list is specified, consider K to be zero.

42The meaning of a namespace-or-type-name is determined as follows:

43If the namespace-or-type-name is a qualified-alias-member, the meaning is as specified in §16.7.

44Otherwise, if the namespace-or-type-name is of the form I or of the form I<A1, ..., AK>:

98

Chapter 10 Basic concepts

1o If K is zero and the namespace-or-type-name appears within the body of a generic method

2declaration (§26.6) and if that declaration includes a type parameter (§26.1.1) with name I, then the

3namespace-or-type-name refers to that type parameter.

4o Otherwise, if the namespace-or-type-name appears within the body of a type declaration, then for

5each instance type T (§26.1.2), starting with the instance type of that type declaration and continuing

6with the instance type of each enclosing class or struct declaration (if any):

7If K is zero and the declaration of T includes a type parameter with name I, then the namespace-

8

or-type-name refers to that type parameter.

9

Otherwise, if T contains a nested accessible type having name I and K type parameters, then the

10

namespace-or-type-name refers to that type constructed with the given type arguments. If there

11

is more than one such type, the type declared within the more derived type is selected. [Note:

12

Non-type members (constants, fields, methods, properties, indexers, operators, instance

13

constructors, destructors, and static constructors) and type members with a different number of

14

type parameters are ignored when determining the meaning of the namespace-or-type-name. end

15

note]

16o Otherwise, for each namespace N, starting with the namespace in which the namespace-or-type-

17name occurs, continuing with each enclosing namespace (if any), and ending with the global

18namespace, the following steps are evaluated until an entity is located:

19If K is zero and I is the name of a namespace in N, then:

20

o If the location where the namespace-or-type-name occurs is enclosed by a namespace

21

declaration for N and the namespace declaration contains an extern-alias-directive or using-

22

alias-directive that associates the name I with a namespace or type, then the namespace-or-

23

type-name is ambiguous and a compile-time error occurs.

24o Otherwise, the namespace-or-type-name refers to the namespace named I in N.

25Otherwise, if N contains an accessible type having name I and K type parameters, then:

26

o If K is zero and the location where the namespace-or-type-name occurs is enclosed by a

27

namespace declaration for N and the namespace declaration contains an extern-alias-

28

directive or using-alias-directive that associates the name I with a namespace or type, then

29

the namespace-or-type-name is ambiguous and a compile-time error occurs.

30

o Otherwise, the namespace-or-type-name refers to the type constructed with the given type

31

arguments.

32

Otherwise, if the location where the namespace-or-type-name occurs is enclosed by a

33

namespace declaration for N:

34

o If K is zero and the namespace declaration contains an extern-alias-directive or using-alias-

35

directive that associates the name I with an imported namespace or type, then the

36

namespace-or-type-name refers to that namespace or type.

37

o Otherwise, if the namespaces imported by the using-namespace-directives of the namespace

38

declaration contain exactly one type having name I and K type parameters, then the

39

namespace-or-type-name refers to that type constructed with the given type arguments.

40

o Otherwise, if the namespaces imported by the using-namespace-directives of the namespace

41

declaration contain more than one type having name I and K type parameters, then the

42

namespace-or-type-name is ambiguous and an error occurs.

43o Otherwise, the namespace-or-type-name is undefined and a compile-time error occurs.

44Otherwise, the namespace-or-type-name is of the form N.I or of the form N.I<A1, ..., AK>. N is first

45resolved as a namespace-or-type-name. If the resolution of N is not successful, a compile-time error

46occurs. Otherwise, N.I or N.I<A1, ..., AK> is resolved as follows:

99

C# LANGUAGE SPECIFICATION

1o If K is zero and N refers to a namespace and N contains a nested namespace with name I, then the

2namespace-or-type-name refers to that nested namespace.

3o Otherwise, if N refers to a namespace and N contains an accessible type having name I and K type

4parameters, then the namespace-or-type-name refers to that type constructed with the given type

5arguments.

6o Otherwise, if N refers to a (possibly constructed) class or struct type and N contains a nested

7accessible type having name I and K type parameters, then the namespace-or-type-name refers to

8that type constructed with the given type arguments. If there is more than one such type, the type

9declared within the more derived type is selected.

10o Otherwise, N.I is an invalid namespace-or-type-name, and a compile-time error occurs.

11A namespace-or-type-name is permitted to reference a static class (§17.1.1.3) if

12The namespace-or-type-name is the T in a namespace-or-type-name of the form T.I, or

13The namespace-or-type-name is the T in a typeof-expression (§14.5.11) of the form typeof(T)

1410.8.1 Unqualified name

15Every namespace declaration and type declaration has an unqualified name determined as follows:

16For a namespace declaration, the unqualified name is the qualified-identifier specified in the declaration.

17For a type declaration with no type-parameter-list, the unqualified name is the identifier specified in the

18declaration.

19For a type declaration with K type parameters, the unqualified name is the identifier specified in the

20declaration, followed by the < token, K-1 commas and the > token.

2110.8.2 Fully qualified names

22Every namespace declaration and type declaration has a fully qualified name, which uniquely identifies the

23namespace or type amongst all others. The fully qualified name of a namespace or type declaration with

24unqualified name N is determined as follows:

25If the declaration is contained directly in a compilation unit and not nested in any other declaration, its

26fully qualified name is N.

27Otherwise, its fully qualified name is S.N, where S is the fully qualified name of the immediately

28enclosing namespace or type declaration.

29In other words, the fully qualified name of a declaration is the complete hierarchical path of identifiers (and

30generic dimensionality specifiers) that lead to the type or namespace, starting from the global namespace.

31The fully qualified name of a declaration shall uniquely identify the namespace, non-generic type or generic

32instance type (§26.1.2) associated with the declaration. It is a compile-time error for the same fully qualified

33name to refer to two distinct entities. In particular:

34It is an error for both a namespace declaration and a type declaration to have the same fully qualified

35name.

36It is an error for two different kinds of type declarations to have the same fully qualified name (for

37example, if both a struct and class declaration have the same fully qualified name).

38It is an error for a type declaration without the partial modifier to have the same fully qualified name

39as another type declaration (§17.1.4).

40[Example: The example below shows several namespace and type declarations along with their associated

41fully qualified names.

42

class A {}

// A

100

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