Salakhetdinov Shamil
mcp2004 at mail.ru
Tue May 1 09:22:15 CDT 2012
Hi Gustav,
Very good!
I'd just have refactored it a bit:
public static bool CompareObjects3<T>(T o1, T o2) where T : class
{
if (o1 == null || o2 == null)
return (o1 == null && o2 == null);
return o1.Equals(o2);
}
Thank you.
-- Shamil
Tue, 01 May 2012 15:18:57 +0200 от "Gustav Brock" <Gustav at cactus.dk>:
> Hi Shamil
>
> How about:
>
> If (o1 == null || o2 == null)
> {
> return (o1 == null && o2 == null);
> }
> else
> {
> return o1.Equals(o2);
> }
>
> /gustav
>
>
> >>> mcp2004 at mail.ru 01-05-2012 14:34 >>>
> 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
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>