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

MiniValidationPlus namespaces #3

Merged
merged 3 commits into from
Jul 16, 2024
Merged
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
6 changes: 3 additions & 3 deletions MiniValidationPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{751FE268-A79
src\Directory.Build.props = src\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidation", "src\MiniValidation\MiniValidation.csproj", "{60C03B53-10AC-4D37-BA95-7EEFE2FC61FC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidationPlus", "src\MiniValidationPlus\MiniValidationPlus.csproj", "{60C03B53-10AC-4D37-BA95-7EEFE2FC61FC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{BF473532-A97B-4CEE-9673-9D4B57D8C1C4}"
EndProject
Expand All @@ -18,7 +18,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Web", "samples\Samp
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4CF82AD1-D050-422E-99D5-454AE28D6A11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidation.UnitTests", "tests\MiniValidation.UnitTests\MiniValidation.UnitTests.csproj", "{4D247E44-6CF5-4A15-A2D3-09E40753874B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidationPlus.UnitTests", "tests\MiniValidationPlus.UnitTests\MiniValidationPlus.UnitTests.csproj", "{4D247E44-6CF5-4A15-A2D3-09E40753874B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CDE0DB87-BF92-4F36-B305-B73CE116DD45}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -30,7 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ThirdPartyNotices.txt = ThirdPartyNotices.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidation.Benchmarks", "tests\MiniValidation.Benchmarks\MiniValidation.Benchmarks.csproj", "{AFA1AA61-E230-48C8-B12B-6561E2124210}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniValidationPlus.Benchmarks", "tests\MiniValidationPlus.Benchmarks\MiniValidationPlus.Benchmarks.csproj", "{AFA1AA61-E230-48C8-B12B-6561E2124210}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion samples/Samples.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using MiniValidation;
using MiniValidationPlus;

var nameAndCategory = args.Length > 0 ? args[0] : null;

Expand Down
2 changes: 1 addition & 1 deletion samples/Samples.Console/Samples.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MiniValidation\MiniValidation.csproj" />
<ProjectReference Include="..\..\src\MiniValidationPlus\MiniValidationPlus.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion samples/Samples.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http.HttpResults;
using MiniValidation;
using MiniValidationPlus;

var builder = WebApplication.CreateBuilder(args);

Expand Down
2 changes: 1 addition & 1 deletion samples/Samples.Web/Samples.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MiniValidation\MiniValidation.csproj" />
<ProjectReference Include="..\..\src\MiniValidationPlus\MiniValidationPlus.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace MiniValidation;
namespace MiniValidationPlus;

/// <summary>
/// An <see cref="IDictionary{TKey, TValue}"/> type to hold a small amount of items (10 or less in the common case).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;

namespace MiniValidation;
namespace MiniValidationPlus;

/// <summary>
/// Provides a way for an object to be validated asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace MiniValidation;
namespace MiniValidationPlus;

/// <summary>
/// Contains methods and properties for performing validation operations with <see cref="Validator"/> on objects whos properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System.Reflection;

namespace MiniValidation
namespace MiniValidationPlus
{
/// <summary>
/// Helper for non-nullable reference types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Diagnostics;
using System.Reflection;

namespace MiniValidation
namespace MiniValidationPlus
{
internal static class PropertyHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace MiniValidation;
namespace MiniValidationPlus;

/// <summary>
/// Indicates that a property should be ignored during recursive validation when using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
using System.Reflection;
using System.Threading;

namespace MiniValidation;
namespace MiniValidationPlus;

internal class TypeDetailsCache
{
private static readonly PropertyDetails[] _emptyPropertyDetails = Array.Empty<PropertyDetails>();
private readonly ConcurrentDictionary<Type, (PropertyDetails[] Properties, bool RequiresAsync)> _cache = new();
#if NET6_0_OR_GREATER
private NonNullablePropertyHelper _nonNullablePropertyHelper = new();
#endif

public (PropertyDetails[] Properties, bool RequiresAsync) Get(Type? type)
{
Expand Down Expand Up @@ -82,6 +79,10 @@ private void Visit(Type type, HashSet<Type> visited, ref bool requiresAsync)
var hasPropertiesOfOwnType = false;
var hasValidatableProperties = false;

#if NET6_0_OR_GREATER
var nonNullablePropertyHelper = new NonNullablePropertyHelper();
#endif

foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
{
if (property.GetIndexParameters().Length > 0)
Expand All @@ -94,7 +95,7 @@ private void Visit(Type type, HashSet<Type> visited, ref bool requiresAsync)
validationAttributes ??= Array.Empty<ValidationAttribute>();

#if NET6_0_OR_GREATER
var isNonNullableReferenceType = _nonNullablePropertyHelper.IsNonNullableReferenceType(property);
var isNonNullableReferenceType = nonNullablePropertyHelper.IsNonNullableReferenceType(property);
#else
var isNonNullableReferenceType = false;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MiniValidation\MiniValidation.csproj" />
<ProjectReference Include="..\..\src\MiniValidationPlus\MiniValidationPlus.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using MiniValidation;
using MiniValidationPlus;

BenchmarkRunner.Run<Benchmarks>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<ItemGroup>
<Using Include="System.ComponentModel.DataAnnotations" />
<Using Include="Xunit" />
<Using Include="MiniValidation" />
<ProjectReference Include="..\..\src\MiniValidation\MiniValidation.csproj" />
<Using Include="MiniValidationPlus" />
<ProjectReference Include="..\..\src\MiniValidationPlus\MiniValidationPlus.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace MiniValidation.UnitTests;
namespace MiniValidationPlus.UnitTests;

public class NonNullablePropertyHelperTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;

namespace MiniValidation.UnitTests;
namespace MiniValidationPlus.UnitTests;

public class Recursion
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;

namespace MiniValidation.UnitTests;
namespace MiniValidationPlus.UnitTests;

class TestType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;

namespace MiniValidation.UnitTests;
namespace MiniValidationPlus.UnitTests;

public class TryValidate
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel;

namespace MiniValidation.UnitTests
namespace MiniValidationPlus.UnitTests
{
internal static class TypeDescriptorExtensions
{
Expand Down
Loading