(bugfix): GetOperation should not throw exception

This commit is contained in:
Maksym Sadovnychyy 2024-12-14 23:56:07 +01:00
parent 9982ee3a8e
commit b17ac0a1d7
3 changed files with 8 additions and 6 deletions

View File

@ -2001,11 +2001,13 @@ var patch = new SomePatchRequestModel {
} }
}; };
// Deconstruct the patch field // Extract operation per field
var usernmae = patch.Username; var usernmae = patch.Username;
var operation = GetOperation(nameOf(patch.Username); if (TryGetOperation(nameOf(patch.Username), out operation)) {
Console.WriteLine($"Operation: {operation}, Value: {value}");
}
Console.WriteLine($"Operation: {operation}, Value: {value}");
``` ```
--- ---

View File

@ -15,8 +15,8 @@ public abstract class PatchRequestModelBase : RequestModelBase {
.Where(prop => prop.Name != nameof(Operations)) .Where(prop => prop.Name != nameof(Operations))
.Any(prop => prop.GetValue(this) != null); .Any(prop => prop.GetValue(this) != null);
public PatchOperation GetOperation(string propertyName) { public bool TryGetOperation(string propertyName, out PatchOperation operation) {
return Operations[propertyName]; return Operations.TryGetValue(propertyName, out operation);
} }
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {

View File

@ -8,7 +8,7 @@
<!-- NuGet package metadata --> <!-- NuGet package metadata -->
<PackageId>MaksIT.Core</PackageId> <PackageId>MaksIT.Core</PackageId>
<Version>1.2.4</Version> <Version>1.2.5</Version>
<Authors>Maksym Sadovnychyy</Authors> <Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company> <Company>MAKS-IT</Company>
<Product>MaksIT.Core</Product> <Product>MaksIT.Core</Product>