Salakhetdinov Shamil
mcp2004 at mail.ru
Tue May 1 07:34:06 CDT 2012
Hi All --
Sorry I'm posting C# code snippet here as my question/quick poll is more about coding style than anything else:
I have occasionally got browsing through the following CodePlex WCF Community source code:
http://wcf.codeplex.com/SourceControl/changeset/view/66aa503c963c#WCFJQuery%2fTest%2fMicrosoft.Runtime.Serialization.Json.FunctionalTests%2fCommon%2fUtil.cs
...
public static bool CompareObjects<T>(T o1, T o2) where T : class
{
if ((o1 == null) != (o2 == null))
{
return false;
}
return (o1 == null) || o1.Equals(o2);
}
...
And I have got stuck first trying to get its logic.
Would you consider the above code more professional and maintainable and effective than the following "mere mortals" code version? If Yes/No - why?
public static bool CompareObjects2<T>(T o1, T o2) where T : class
{
if (o1 == null && o2 == null) return true;
if (o1 != null && o2 == null) return false;
if (o1 == null && o2 != null) return false;
return o1.Equals(o2);
}
Thank you ;)
-- Shamil