Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification 13 Conversions 13.4 User-defined conversions 13.4.2 Evaluation of user-defined conversions
Paragraph 11 A user-defined conversion converts a value from its type, called the source type, to another type, called the target type. 2 Evaluation of a user-defined conversion centers on finding the most specific user-defined conversion operator for the particular source and target types. 3 This determination is broken into several steps:
Paragraph 21 Once a most specific user-defined conversion operator has been identified, the actual execution of the user-defined conversion involves up to three steps:
- 4 Finding the set of classes and structs from which user-defined conversion operators will be considered. 5 This set consists of the source type and its base classes and the target type and its base classes (with the implicit assumptions that only classes and structs can declare user-defined operators, and that non-class types have no base classes).
- 6 From that set of types, determining which user-defined conversion operators are applicable. 7 For a conversion operator to be applicable, it must be possible to perform a standard conversion (§13.3) from the source type to the operand type of the operator, and it must be possible to perform a standard conversion from the result type of the operator to the target type.
- 8 From the set of applicable user-defined operators, determining which operator is unambiguously the most specific. 9 In general terms, the most specific operator is the operator whose operand type is "closest" to the source type and whose result type is "closest" to the target type. 10 The exact rules for establishing the most specific user-defined conversion operator are defined in the following sections.
Paragraph 31 Evaluation of a user-defined conversion never involves more than one user-defined conversion operator. 2 In other words, a conversion from type S to type T will never first execute a user-defined conversion from S to X and then execute a user-defined conversion from X to T.
Paragraph 41 Exact definitions of evaluation of user-defined implicit or explicit conversions are given in the following sections. 2 The definitions make use of the following terms:
- 2 First, if required, performing a standard conversion from the source type to the operand type of the user-defined conversion operator.
- 3 Next, invoking the user-defined conversion operator to perform the conversion.
- 4 Finally, if required, performing a standard conversion from the result type of the user-defined conversion operator to the target type.
- 3 If a standard implicit conversion (§13.3.1) exists from a type A to a type B, and if neither A nor B are interface-types, then A is said to be encompassed by B, and B is said to encompass A.
- 4 The most encompassing type in a set of types is the one type that encompasses all other types in the set. 5 If no single type encompasses all other types, then the set has no most encompassing type. 6 In more intuitive terms, the most encompassing type is the "largest" type in the set-the one type to which each of the other types can be implicitly converted.
- 7 The most encompassed type in a set of types is the one type that is encompassed by all other types in the set. 8 If no single type is encompassed by all other types, then the set has no most encompassed type. 9 In more intuitive terms, the most encompassed type is the "smallest" type in the set-the one type that can be implicitly converted to each of the other types.
|Jagger Software Ltd|
|Company # 4070126|
|VAT # 762 5213 42|