S
shapper
Hello,
I created a method to check if two objects (string, int, ...) are
equal.
The objects should only be compared if they are not null or in case of
a string also empty.
I am using the following:
// Equal
public static bool Equal(object value, object compare) {
CaseInsensitiveComparer comparer =
CaseInsensitiveComparer.DefaultInvariant;
if (value == null ? true : (String.IsNullOrEmpty(value.ToString
()) ? true : false)) return true;
if (compare == null ? true : (String.IsNullOrEmpty
(compare.ToString()) ? true : false)) return true;
return comparer.Compare(value, compare) == 0;
} // Equal
This is working but am I checking all the cases where the Compare
would throw an error?
Thanks,
Miguel
I created a method to check if two objects (string, int, ...) are
equal.
The objects should only be compared if they are not null or in case of
a string also empty.
I am using the following:
// Equal
public static bool Equal(object value, object compare) {
CaseInsensitiveComparer comparer =
CaseInsensitiveComparer.DefaultInvariant;
if (value == null ? true : (String.IsNullOrEmpty(value.ToString
()) ? true : false)) return true;
if (compare == null ? true : (String.IsNullOrEmpty
(compare.ToString()) ? true : false)) return true;
return comparer.Compare(value, compare) == 0;
} // Equal
This is working but am I checking all the cases where the Compare
would throw an error?
Thanks,
Miguel