CapyKit/Documentation/Help/T_CapyKit_PropertyComparer_2.md
Jordan Wages 735d7c4c91 Documentation + Unfinished SecurityHelper
Committing the unfinished changes to the SecurityHelper as I flesh it out during the migration. Also starting a documentation folder powered by Sandcastle.
2024-04-19 23:12:24 -05:00

4.7 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+6cdd805be49c3b769a116584ea6904955ecd820d

C#

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

VB

Public Class PropertyComparer(Of T, U)
	Implements IEqualityComparer(Of T)

C++

generic<typename T, typename U>
public ref class PropertyComparer : 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)

See Also

Reference

CapyKit Namespace