Skip to content

Commit

Permalink
Demonstrate validation code generation problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Jun 23, 2023
1 parent 52ebc1b commit 1bdd925
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Libraries/L1/BaseOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace ValidationTest;

public class BaseOptions
{
[Timeout]
public int Prop1 { get; set; }
}
12 changes: 12 additions & 0 deletions src/Libraries/L1/BaseOptionsValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options.Validation;

namespace ValidationTest;

[OptionsValidator]
internal sealed partial class BaseOptionsValidator : IValidateOptions<BaseOptions>
{
}
15 changes: 15 additions & 0 deletions src/Libraries/L1/L1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseOptionsValidationGenerator>true</UseOptionsValidationGenerator>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.Options.Validation\Microsoft.Extensions.Options.Validation.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="OpenTelemetry" />
</ItemGroup>
</Project>
Empty file added src/Libraries/L1/L1.json
Empty file.
16 changes: 16 additions & 0 deletions src/Libraries/L1/TimeoutAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel.DataAnnotations;

namespace ValidationTest;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
internal sealed class TimeoutAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object? value, ValidationContext? validationContext)
{
return ValidationResult.Success!;
}
}
12 changes: 12 additions & 0 deletions src/Libraries/L2/ExtOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.DataAnnotations;

namespace ValidationTest;

public class ExtOptions : BaseOptions
{
[Range(0, 10)]
public int Prop2 { get; set; }
}
12 changes: 12 additions & 0 deletions src/Libraries/L2/ExtOptionsValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options.Validation;

namespace ValidationTest;

[OptionsValidator]
internal sealed partial class ExtOptionsValidator : IValidateOptions<ExtOptions>
{
}
10 changes: 10 additions & 0 deletions src/Libraries/L2/L2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseOptionsValidationGenerator>true</UseOptionsValidationGenerator>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\L1\L1.csproj" />
</ItemGroup>
</Project>
Empty file added src/Libraries/L2/L2.json
Empty file.

0 comments on commit 1bdd925

Please sign in to comment.