CommunityToolkit icon indicating copy to clipboard operation
CommunityToolkit copied to clipboard

Incorrect method used in Guard example

Open FrithjofNZ opened this issue 9 months ago • 0 comments

Type of issue

Code doesn't work

Description

You provided two examples, one without using the Guard class, one with using the Guard class. Both methods are supposed to be equivalent in functionality, but there is one clause that checks for the opposite. This line Guard.HasSizeGreaterThanOrEqualTo(array, 10);

should be Guard.HasSizeLessThan(array, 10); to be equivalent.

The non-guard code throws an exception when the input array's size is 10 or greater. Translated to a Guard clause, it means you want to ensure that the array has less than 10 elements, which would be Guard.HasSizeLessThan(array, 10);

Page URL

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/diagnostics/guard

Content source URL

https://github.com/MicrosoftDocs/CommunityToolkit/blob/main/docs/diagnostics/Guard.md

Document Version Independent Id

17c0e81d-a3e0-a8d5-3214-8d6272bff50b

Article author

@Sergio0694

Metadata

  • ID: 17c0e81d-a3e0-a8d5-3214-8d6272bff50b
  • Service: dotnet-communitytoolkit

FrithjofNZ avatar Feb 02 '25 23:02 FrithjofNZ