CapyKit Documentation
  • Introduction
  • Getting Started
  • API Reference
    • CapyKit
      • CapyEventArgs
      • CapyEventHandler
      • CapyEventReporter
      • Color
      • EncryptedValue<T>
      • EventLevel
      • IPasswordAlgorithm
      • NamedColor
      • Password
      • Pbkdf2Algorithm
      • PoolItem<T>
      • Pool<T>
      • PropertyComparer<T, U>
    • CapyKit.Attributes
      • EnumerationAttribute<T>
      • EnumerationDescriptionAttribute
      • ValueFormatAttribute
    • CapyKit.Enumerations
      • MeasurementSystem
    • CapyKit.Extensions
      • EnumerationExtensions
      • LINQExtensions
      • ObjectExtensions
      • StringExtensions
    • CapyKit.Helpers
      • CalculationHelper
      • CompressionHelper
      • EncryptionHelper
      • IEncryptionAlgorithm
      • KeyHelper
      • LanguageHelper
      • SecurityHelper
      • SerializationHelper
      • SettingsHelper
      • ValidCharacterCollection
Search Results for

    Show / Hide Table of Contents
    • Introduction
    • Getting Started
    • API Reference
      • CapyKit
        • CapyEventArgs
        • CapyEventHandler
        • CapyEventReporter
        • Color
        • EncryptedValue<T>
        • EventLevel
        • IPasswordAlgorithm
        • NamedColor
        • Password
        • Pbkdf2Algorithm
        • PoolItem<T>
        • Pool<T>
        • PropertyComparer<T, U>
      • CapyKit.Attributes
        • EnumerationAttribute<T>
        • EnumerationDescriptionAttribute
        • ValueFormatAttribute
      • CapyKit.Enumerations
        • MeasurementSystem
      • CapyKit.Extensions
        • EnumerationExtensions
        • LINQExtensions
        • ObjectExtensions
        • StringExtensions
      • CapyKit.Helpers
        • CalculationHelper
        • CompressionHelper
        • EncryptionHelper
        • IEncryptionAlgorithm
        • KeyHelper
        • LanguageHelper
        • SecurityHelper
        • SerializationHelper
        • SettingsHelper
        • ValidCharacterCollection

    Class PropertyComparer<T, U>

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

    Inheritance
    object
    PropertyComparer<T, U>
    Implements
    IEqualityComparer<T>
    Namespace: CapyKit
    Assembly: CapyKit.dll
    Syntax
    public class PropertyComparer<T, U> : IEqualityComparer<T>
    Type Parameters
    Name Description
    T

    Generic type parameter of the parent object.

    U

    Generic type parameter of the property value.

    Examples

    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(Func<T, U>)

    Constructor.

    Declaration
    public PropertyComparer(Func<T, U> expression)
    Parameters
    Type Name Description
    Func<T, U> expression

    The expression.

    Methods

    Equals(T, T)

    Determines whether the specified properties are equal.

    Declaration
    public bool Equals(T x, T y)
    Parameters
    Type Name Description
    T x

    The first object of type T to compare.

    T y

    The second object of type T to compare.

    Returns
    Type Description
    bool

    true if the specified objects are equal; otherwise, false.

    GetHashCode(T)

    Returns a hash code for the specified object.

    Declaration
    public int GetHashCode(T obj)
    Parameters
    Type Name Description
    T obj

    The object for which a hash code is to be returned.

    Returns
    Type Description
    int

    A hash code for the specified object.

    Exceptions
    Type Condition
    ArgumentNullException

    The type of obj is a reference type and obj is null.

    Implements

    IEqualityComparer<T>
    In this article
    Back to top Generated by DocFX