CapyKit/Docs/_site/api/CapyKit.PropertyComparer-2.html

192 lines
8.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Class PropertyComparer&lt;T, U&gt; | CapyKit Documentation </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="title" content=" Class PropertyComparer&lt;T, U&gt; | CapyKit Documentation ">
<link rel="icon" href="../favicon.ico">
<link rel="stylesheet" href="../public/docfx.min.css">
<link rel="stylesheet" href="../public/main.css">
<meta name="docfx:navrel" content="../toc.html">
<meta name="docfx:tocrel" content="../toc.html">
<meta name="docfx:rel" content="../">
<meta name="loc:inThisArticle" content="In this article">
<meta name="loc:searchResultsCount" content="{count} results for &quot;{query}&quot;">
<meta name="loc:searchNoResults" content="No results for &quot;{query}&quot;">
<meta name="loc:tocFilter" content="Filter by title">
<meta name="loc:nextArticle" content="Next">
<meta name="loc:prevArticle" content="Previous">
<meta name="loc:themeLight" content="Light">
<meta name="loc:themeDark" content="Dark">
<meta name="loc:themeAuto" content="Auto">
<meta name="loc:changeTheme" content="Change theme">
<meta name="loc:copy" content="Copy">
<meta name="loc:downloadPdf" content="Download PDF">
<script type="module" src="./../public/docfx.min.js"></script>
<script>
const theme = localStorage.getItem('theme') || 'auto'
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
</script>
</head>
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
<header class="bg-body border-bottom">
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
<div class="container-xxl flex-nowrap">
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../logo.svg" alt="CapyKit Documentation">
CapyKit Documentation
</a>
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-three-dots"></i>
</button>
<div class="collapse navbar-collapse" id="navpanel">
<div id="navbar">
<form class="search" role="search" id="search">
<i class="bi bi-search"></i>
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
</form>
</div>
</div>
</div>
</nav>
</header>
<main class="container-xxl">
<div class="content">
<div class="actionbar">
<nav id="breadcrumb"></nav>
</div>
<article data-uid="">
<h1 id="CapyKit_PropertyComparer_2"> Class PropertyComparer&lt;T, U&gt;</h1>
<p>Namespace: <a href="CapyKit.html">CapyKit</a><br>
Assembly: CapyKit.dll</p>
<p>A object comparer that can accept a lambda expression to compare properties.</p>
<pre><code class="lang-csharp">public class PropertyComparer&lt;T, U&gt; : IEqualityComparer&lt;T&gt;
</code></pre>
<h4 id="type-parameters">Type Parameters</h4>
<p><code>T</code></p>
<p>Generic type parameter of the parent object.</p>
<p><code>U</code></p>
<p>Generic type parameter of the property value.</p>
<h4 id="inheritance">Inheritance</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a>
<a href="CapyKit.PropertyComparer-2.html">PropertyComparer&lt;T, U&gt;</a></p>
<h4 id="implements">Implements</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.collections.generic.iequalitycomparer-1">IEqualityComparer&lt;T&gt;</a></p>
<h4 id="inherited-members">Inherited Members</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>,
<a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a></p>
<h4 id="extension-methods">Extension Methods</h4>
<p><a href="CapyKit.Extensions.ObjectExtensions.html#CapyKit_Extensions_ObjectExtensions_UpdateProperties__1___0___0_">ObjectExtensions.UpdateProperties&lt;PropertyComparer&lt;T, U&gt;&gt;(PropertyComparer&lt;T, U&gt;, PropertyComparer&lt;T, U&gt;)</a>,
<a href="CapyKit.Extensions.ObjectExtensions.html#CapyKit_Extensions_ObjectExtensions_UpdateProperties_System_Object_System_Object_">ObjectExtensions.UpdateProperties(object, object)</a></p>
<h2 id="examples">Examples</h2>
<p>using System;
using System.Collections.Generic;
using System.Linq;</p>
<p>class Program
{
static void Main(string[] args)
{
var people = new List&lt;Person&gt;
{
new Person { Name = &quot;Alice&quot;, Age = 30 }, new Person { Name = &quot;Bob&quot;, Age = 30 }, new
Person { Name = &quot;Charlie&quot;, Age = 35 }
};</p>
<pre><code> var comparer = new PropertyComparer&lt;Person, int&gt;(p =&gt; p.Age);
var distinctPeople = people.Distinct(comparer).ToList();
foreach (var person in distinctPeople)
{
Console.WriteLine($&quot;{person.Name} - {person.Age}&quot;);
}
}
</code></pre>
<p>}</p>
<p>class Person
{
public string Name { get; set; }
public int Age { get; set; }
}</p>
<h2 id="constructors">Constructors</h2>
<h3 id="CapyKit_PropertyComparer_2__ctor_System_Func__0__1__"> PropertyComparer(Func&lt;T, U&gt;)</h3>
<p>Constructor.</p>
<pre><code class="lang-csharp">public PropertyComparer(Func&lt;T, U&gt; expression)
</code></pre>
<h4 id="parameters">Parameters</h4>
<p><code>expression</code> <a href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, U&gt;</p>
<p>The expression.</p>
<h2 id="methods">Methods</h2>
<h3 id="CapyKit_PropertyComparer_2_Equals__0__0_"> Equals(T, T)</h3>
<p>Determines whether the specified properties are equal.</p>
<pre><code class="lang-csharp">public bool Equals(T x, T y)
</code></pre>
<h4 id="parameters-1">Parameters</h4>
<p><code>x</code> T</p>
<p>The first object of type <code class="typeparamref">T</code> to compare.</p>
<p><code>y</code> T</p>
<p>The second object of type <code class="typeparamref">T</code> to compare.</p>
<h4 id="returns">Returns</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></p>
<p><a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">true</a> if the specified objects are equal; otherwise,
<a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool">false</a>.</p>
<h3 id="CapyKit_PropertyComparer_2_GetHashCode__0_"> GetHashCode(T)</h3>
<p>Returns a hash code for the specified object.</p>
<pre><code class="lang-csharp">public int GetHashCode(T obj)
</code></pre>
<h4 id="parameters-2">Parameters</h4>
<p><code>obj</code> T</p>
<p>The <span class="xref">System.Object</span> for which a hash code is to be returned.</p>
<h4 id="returns-1">Returns</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></p>
<p>A hash code for the specified object.</p>
<h4 id="exceptions">Exceptions</h4>
<p><a href="https://learn.microsoft.com/dotnet/api/system.argumentnullexception">ArgumentNullException</a></p>
<p>The type of <code class="paramref">obj</code> is a reference type and
<code class="paramref">obj</code> is
<a href="https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null">null</a>.</p>
</article>
<div class="contribution d-print-none">
</div>
<div class="next-article d-print-none border-top" id="nextArticle"></div>
</div>
<div class="affix">
<nav id="affix"></nav>
</div>
</main>
<div class="container-xxl search-results" id="search-results"></div>
<footer class="border-top text-secondary">
<div class="container-xxl">
<div class="flex-fill">
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
</div>
</div>
</footer>
</body>
</html>