From af312270a351743c4db11f727b8fffb0a1aeb4e0 Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Mon, 20 Nov 2023 11:14:04 +0300 Subject: [PATCH] Hide Base64Attribute in .NET8 onwards in favour of Base64StringAttribute (#188) --- src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs | 5 ++++- .../Base64AttributeTests.cs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs b/src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs index 0b9bc2e..5f353fa 100644 --- a/src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs +++ b/src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs @@ -1,4 +1,5 @@ -namespace System.ComponentModel.DataAnnotations; +#if !NET8_0_OR_GREATER +namespace System.ComponentModel.DataAnnotations; /// /// Specifies that a data field value is a well-formed base 64 string. @@ -15,6 +16,7 @@ public Base64Attribute() : base("The field {0} must be a valid base64 string.") public override bool IsValid(object? value) { if (value is not string s || string.IsNullOrEmpty(s)) return true; + // attempt to convert from base64 try { @@ -27,3 +29,4 @@ public override bool IsValid(object? value) } } } +#endif diff --git a/tests/Tingle.Extensions.DataAnnotations.Tests/Base64AttributeTests.cs b/tests/Tingle.Extensions.DataAnnotations.Tests/Base64AttributeTests.cs index 7f173bc..e6f8977 100644 --- a/tests/Tingle.Extensions.DataAnnotations.Tests/Base64AttributeTests.cs +++ b/tests/Tingle.Extensions.DataAnnotations.Tests/Base64AttributeTests.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +#if !NET8_0_OR_GREATER +using System.ComponentModel.DataAnnotations; namespace Tingle.Extensions.DataAnnotations.Tests; @@ -34,3 +35,4 @@ public void Base64_Validation_Works(string testKey, bool expected) record TestModel([property: Base64] string? SomeKey); } +#endif