Skip to content

Commit

Permalink
Hide Base64Attribute in .NET8 onwards in favour of Base64StringAttrib…
Browse files Browse the repository at this point in the history
…ute (#188)
  • Loading branch information
mburumaxwell authored Nov 20, 2023
1 parent 30f4d34 commit af31227
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Tingle.Extensions.DataAnnotations/Base64Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace System.ComponentModel.DataAnnotations;
#if !NET8_0_OR_GREATER
namespace System.ComponentModel.DataAnnotations;

/// <summary>
/// Specifies that a data field value is a well-formed base 64 string.
Expand All @@ -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
{
Expand All @@ -27,3 +29,4 @@ public override bool IsValid(object? value)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
#if !NET8_0_OR_GREATER
using System.ComponentModel.DataAnnotations;

namespace Tingle.Extensions.DataAnnotations.Tests;

Expand Down Expand Up @@ -34,3 +35,4 @@ public void Base64_Validation_Works(string testKey, bool expected)

record TestModel([property: Base64] string? SomeKey);
}
#endif

0 comments on commit af31227

Please sign in to comment.