Conversion operators are unary operations that allow conversion from one type to another. The operator method must be defined as a static method on either the operand or return type. There are two types of conversions:
op_Implicit
op_Explicit
Conversions provide functionality that can’t be generated in other ways, and many languages will not support the use of the conversion operators through special syntax. Therefore, we recommend that the same functionality be made available using the more common ToXxx and FromXxx naming pattern.
Because these operations may exist on the class of their operand type (so-called “from” conversions) and would therefore differ on their return type only, the CLS specifically allows that these two operators be overloaded based on their return type. The CLS, however, also requires that if this form of overloading is used then the language must provide an alternate means for providing the same functionality since not all CLS languages will implement operators with special syntax.
CLS Rule 38: If either op_Implicit or op_Explicit is overloaded on its return type, an alternate means of providing the coercion must be provided.
CLS Rule 39: The functionality provided by op_Implicit or op_Explicit should also be provided through the FromXxx and ToXxx naming pattern.
CLS (consumer): Where appropriate to the language design, use the existence of op_Implicit and/or op_Explicit in choosing method overloads and generating automatic coercions.
CLS (extender): Where appropriate to the language design allow the definition of implicit or explicit coercion operators to produce the corresponding op_Implicit, op_Explicit, ToXxx, and/or FromXxx methods. Otherwise, if possible, provide a means for explicitly defining those methods including the possibility of overloading op_Implicit and op_Explicit based on return type alone.
CLS (framework): Consider providing coercion operations. When this is done, always provide functionality via FromXxx and ToXxx and consider providing op_Implicit and op_Explicit as well.