Is it possible to overload the “as” or “is” operators
-
13-10-2019 - |
Pergunta
Is this allowed? If not, can this be accomplished inherently by overloading the implicit/explicit conversion operators?
Solução
Is overloading the "is" and "as" operators allowed?
No.
If not, can this be accomplished inherently by overloading the implicit/explicit conversion operators?
No. The "as" and "is" operators tell you what a thing really is. They pay no attention to user-defined conversions.
See
http://blogs.msdn.com/b/ericlippert/archive/2010/09/16/is-is-as-or-is-as-is.aspx
for some more thoughts on the "as" and "is" operators.
Outras dicas
No. Check this: Overloadable Operators and this All C# operators
No, because they are not operators as such, they are keywords of the language.
Also, I'm not sure what you would overload them to and still preserve the semantics of the language spec? Seems like it could be used only for great evil :)