Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Invokes Enumerable::SequenceEqual generic extension method with reflection.
static class DynamicComparer
{
public static bool DynamicEquals<T>(this T value, T other)
{
if (object.Equals(value, default(T)))
{
throw new ArgumentNullException("value");
}
if (object.Equals(other, default(T)))
{
return false;
}
if (value is IEnumerable && other is IEnumerable)
{
var t = typeof(Enumerable);
var meth = t.GetMethods(BindingFlags.Public | BindingFlags.Static)
.Single(m => m.Name.Equals("SequenceEqual") && m.GetParameters().Count() == 2);
var gm = meth.MakeGenericMethod(typeof(T).GetGenericArguments().Single());
return (bool)gm.Invoke(null, new object[] { value, other });
}
return value.Equals(other);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.