ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

Equals

Equals method that lets you specify on what property or field value you want to compare an object on. Also compares the object types. Useful to use in an overridden Equals method of an object.

Source

public static bool Equals<T, TResult>(this T obj, object obj1, Func<T, TResult> selector)
{
    return obj1 is T && selector(obj).Equals(selector((T)obj1));
}

Example

When used inside a custom "File" class: public override bool Equals(object obj)
{
    return this.Equals(obj, x => x.Path);
}

Author: joaomgcd

Submitted on: 18 mrt 2009

Language: C#

Type: System.Object

Views: 5486