Question

I have de-compiled some old code from a legacy VB.NET app using ILSply and this line has appeared:

Operators.ConditionalCompareObjectEqual(safeDataReader["isLoader"], -1, false)

I'm aware this is compiler generated, but its not advised that this code is used in application source code. My question is why is this the case and what should it be in 'normal' code?

Was it helpful?

Solution

The documentation for the method says it right there:

Represents the overloaded Visual Basic equals (=) operator.

Why? I don't "know", but it's easy to make an educated guess.

The semantics of the "=" operator in VB.NET are just a bit different from those of C# and the standard Object.Equals(). The semantics are inherited from VB6 and cannot be changed for backward compatibility reasons. Obviously this method implements the VB6 semantics for the compiler.

It would make an interesting read to come up with a systematic analysis of the differences.

Further thoughts:

The reason it's "not recommended" is because there is no reason to call the method from VB.NET: just use =. In C#, there is no particular reason to invoke the VB6 semantics so the method doesn't make a lot of sense there either.

Obviously, if you are compiling C# code generated from VB.NET, then those are special circumstances: calling the method is the right thing to do, unless you're willing to take the time to analyze the code and prove to yourself that the standard = cn be substituted safely.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top