Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve KeyEquality docs #2643

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions doc/Learn/KeyEquality/rules.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
---
uid: Uno.Extensions.Reactive.Rules
uid: Uno.Extensions.KeyEquality.Rules
---
# Feeds code analyzers

## KE0001

**A record eligible to IKeyEquatable generation must be partial.**
**A record eligible for IKeyEquatable generation must be partial.**

You have a record that has a property that can be used to generate `IKeyEquatable` implementation for that record,
but it was not declared as `partial`.

Add the `partial` modifier on your record, or disable the `IKeyEquatable` implementation generated using `[ImplicitKeyEquality(IsEnabled = false)]` on the record itself or on the whole assembly (not recommended).
Add the `partial` modifier on your record, or turn off the `IKeyEquatable` implementation generated using `[ImplicitKeyEquality(IsEnabled = false)]` on the record itself or the whole assembly (not recommended).

## KE0002

**A record that implements GetKeyHashCode should also implement KeyEquals.**

You have method named `GetKeyHashCode` in your record, but there is no `KeyEquals`.
You have a method named `GetKeyHashCode` in your record, but no `KeyEquals` exist.

If you want to define a custom way to compute _key equality_, you have to implement both the `GetKeyHashCode` and `KeyEquals`.

## KE0003

**A record that implements KeyEquals should also implement GetKeyHashCode.**

You have method named `KeyEquals` in your record, but there is no `GetKeyHashCode`.
You have a method named `KeyEquals` in your record, but there is no `GetKeyHashCode`.

If you want to define a custom way to compute _key equality_, you have to implement both the `GetKeyHashCode` and `KeyEquals`.

## KE0004

**A record flagged with `[ImplicitKeyEquality]` attribute must have an eligible key property**

You have a record that is flagged with `[ImplicitKeyEquality]` attribute, but there is no property that match any of the defined implicit keys.
You have a record flagged with the `[ImplicitKeyEquality]` attribute, but no property matches any of the defined implicit keys.

You should either remove the `[ImplicitKeyEquality]` attribute, either add a valid property name.
You should remove the `[ImplicitKeyEquality]` attribute or add a valid property name.

## KE0005

**A record should have only one matching key property for implicit IKeyEquatable generation.**

You have a record that is eligible for implicit key equality generation, but it has more than one matching implicit key.
The generated implementation of `IKeyEquatable` will use only the first key.
You have a record eligible for implicit key equality generation, but it has more than one matching implicit key. The generated implementation of `IKeyEquatable` will use only the first key.

You should either explicitly flag all needed key properties with the `[Key]` attribute,
either remove/rename properties that should not be used as key.
You should either explicitly flag all needed key properties with the `[Key]` attribute or remove/rename properties that should not be used as keys.

> [!NOTE]
> By default the key equality generation will search for properties named `Id` or `Key`.
> By default, the key equality generation will search for `Id` or `Key` properties.
> You can customize it using the `ImplicitKeyEquality` attribute.
> For instance setting `[assembly:ImplicitKeyEquality("Id", "MyCustomKey")]` on your assembly will no longer search for `Key` properties,
>, For instance, setting `[assembly:ImplicitKeyEquality("Id", "MyCustomKey")]` on your assembly will no longer search for `Key` properties,
> but will instead search for `MyCustomKey` properties.
4 changes: 4 additions & 0 deletions doc/Learn/KeyEquality/toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Overview
href: xref:Uno.Extensions.KeyEquality.Concept
- name: Rules
href: xref:Uno.Extensions.KeyEquality.Rules
Loading