CapyKit/Documentation/Help/T_CapyKit_PropertyComparer_2.md
Jordan Wages 87bd044b31 Settings Helper + Documentation
The `SettingsHelper` is an agnostic way to access settings values uniformly through code. The accessor methods are controlled by the consumer.

Documentation has been a bit wonky. I changed the max number of version number components allowed, so each new build should not create new changes on every single bit of documentation now.
2024-04-22 18:28:21 -05:00

4.6 KiB

PropertyComparer<T, U> Class

A object comparer that can accept a lambda expression to compare properties.

Definition

Namespace: CapyKit
Assembly: CapyKit (in CapyKit.dll) Version: 1.0.0

C#

public class PropertyComparer<T, U> : IEqualityComparer<T>

F#

type PropertyComparer<'T, 'U> = 
    class
        interface IEqualityComparer<'T>
    end
InheritanceObject → PropertyComparer(T, U)
ImplementsIEqualityComparer(T)

Type Parameters

Generic type parameter of the parent object.
Generic type parameter of the property value.

Example

using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var people = new List<Person> { new Person { Name = "Alice", Age = 30 }, new Person { Name = "Bob", Age = 30 }, new Person { Name = "Charlie", Age = 35 } }; var comparer = new PropertyComparer<Person, int>(p => p.Age); var distinctPeople = people.Distinct(comparer).ToList(); foreach (var person in distinctPeople) { Console.WriteLine($"{person.Name} - {person.Age}"); } } } class Person { public string Name { get; set; } public int Age { get; set; } }

Constructors

PropertyComparer(T, U) Constructor.

Methods

Equals(Object) Determines whether the specified object is equal to the current object.
(Inherited from Object)
Equals(T, T) Determines whether the specified properties are equal.
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode() Serves as the default hash function.
(Inherited from Object)
GetHashCode(T) Returns a hash code for the specified object.
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
ToString Returns a string that represents the current object.
(Inherited from Object)

Fields

expression The expression to retrieve the property.

See Also

Reference

CapyKit Namespace