It's mind bending experiencing reading code like :
"Aggregation".Equals(evt.Id)) I was unsuccessful in trying to talk the person out of this style, maybe I'm wrong? Or maybe I wasn't articulate enough, hence the post here.
No, it's not justified.
It makes some sense to do this for string comparisons in Java where calling .equals on a string variable can result in a NullPointerException, so:
myString.equals("foo") Can be made safer by doing:
"foo".equals(myString) This is not really relevant in C# which uses the == operator for string comparisons. This is safe to use with null references. The same is true of String.Equals.
== for comparisons, Yoda conditions are often used to prevent accidental assignments in conditions (if (myValue = "foo") then ...). Some languages disallow assignments in condition blocks for this reason. I believe C# is among those? Which would indeed mean it's a lot harder to justify. if (myValue = "foo") { ... } yields a compilation error saying that 'string' cannot be implicitly converted to 'bool'. Even when using if (myBoolValue = true) { ... }, the compiler issues a warning saying that the expression is constant and thr author probably meant to use == instead of =. So yeah, in C# there is usually no need for yoda conditions.
evt.Idbenull? Perhaps. You do not want to call methods onnull."Aggregation"is notnull, for sure. Although, why not==? Yeah, use==instead. If you had a reason not to, you probably should be using an equality comparer.