среда, 17 июня 2015 г.

Prevent implicit casting from null keyword to struct when implicit conversion from string is defined

If your struct has defined implicit conversion from string, then null keyword will be implicitly handled as string and there will be no compiler error.

To prevent this you could define second implicit conversion from any other reference type. Then implicit casting from null keyword becomes ambiguous and will produce error:

Argument type 'null' is not assignable to parameter type 'MyType'

Exactly what we wanted.

Комментариев нет:

Отправить комментарий