Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Add support for .net 4.5 data annotations #2435

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion Nancy.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5734E9DC-CF67-4337-B28E-695280598B88}"
EndProject
Expand Down Expand Up @@ -89,6 +89,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.Demo.Hosting.Kestrel"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.ViewEngines.Spark.Tests", "test\Nancy.ViewEngines.Spark.Tests\Nancy.ViewEngines.Spark.Tests.csproj", "{08C1D823-E8E1-4D86-8F73-A9F3AE8FEFC7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nancy.Demo.Validation", "samples\Nancy.Demo.Validation\Nancy.Demo.Validation.csproj", "{F417B81C-B914-4BFD-8299-6BBD11072B01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -555,6 +557,18 @@ Global
{08C1D823-E8E1-4D86-8F73-A9F3AE8FEFC7}.Release|x64.Build.0 = Release|Any CPU
{08C1D823-E8E1-4D86-8F73-A9F3AE8FEFC7}.Release|x86.ActiveCfg = Release|Any CPU
{08C1D823-E8E1-4D86-8F73-A9F3AE8FEFC7}.Release|x86.Build.0 = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|x64.ActiveCfg = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|x64.Build.0 = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|x86.ActiveCfg = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Debug|x86.Build.0 = Debug|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|Any CPU.Build.0 = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|x64.ActiveCfg = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|x64.Build.0 = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|x86.ActiveCfg = Release|Any CPU
{F417B81C-B914-4BFD-8299-6BBD11072B01}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -598,5 +612,6 @@ Global
{EEEE504F-24AC-4932-9B28-F684AB20FB50} = {5734E9DC-CF67-4337-B28E-695280598B88}
{3AF8D59E-D10A-46DE-97A6-0A6C156F22CD} = {AA791E28-7914-439A-B59A-580B8D8FE95D}
{08C1D823-E8E1-4D86-8F73-A9F3AE8FEFC7} = {058BCE2A-8F81-4404-83D3-844CE030E513}
{F417B81C-B914-4BFD-8299-6BBD11072B01} = {AA791E28-7914-439A-B59A-580B8D8FE95D}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,48 @@
<Compile Include="LoginFixture.cs" />
<Compile Include="TestBootstrapper.cs" />
<Compile Include="TestRootPathProvider.cs" />
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\BaseValidatorAdapterTestFixture.cs">
<Link>BaseValidatorAdapterTestFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\CompareValidatorAdapterFixture.cs">
<Link>CompareValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\CreditCardValidatorAdapterFixture.cs">
<Link>CreditCardValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\DataAnnotationsValidatorFixture.cs">
<Link>DataAnnotationsValidatorFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\DataAnnotationsValidatorFactoryFixture.cs">
<Link>DataAnnotationsValidatorFactoryFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\DefaultValidatableObjectAdapterFixture.cs">
<Link>DefaultValidatableObjectAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\EmailAddressValidatorAdapterFixture.cs">
<Link>EmailAddressValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\EnumDataTypeValidatorAdapterFixture.cs">
<Link>EnumDataTypeValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\FileExtensionsValidatorAdapterFixture.cs">
<Link>FileExtensionsValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\MaxLengthValidatorAdapterFixture.cs">
<Link>MaxLengthValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\MinLengthValidatorAdapterFixture.cs">
<Link>MinLengthValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\PhoneValidatorAdapterFixture.cs">
<Link>PhoneValidatorAdapterFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\PropertyValidatorFixture.cs">
<Link>PropertyValidatorFixture.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotatioins.Tests\UrlValidatorAdapterFixture.cs">
<Link>UrlValidatorAdapterFixture.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Nancy.Testing.MSBuild\Nancy.Testing.csproj">
Expand Down Expand Up @@ -145,6 +187,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Analyzer Include="..\..\packages\FakeItEasy.Analyzer.2.1.0\analyzers\dotnet\cs\FakeItEasy.Analyzer.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
72 changes: 72 additions & 0 deletions samples/Nancy.Demo.Hosting.Self/Nancy.Demo.Hosting.Self.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,78 @@
<Compile Include="Program.cs" />
<Compile Include="TestModule.cs" />
<Compile Include="DemoBootstrapper.cs" />
<Compile Include="..\Nancy.Validation.DataAnnotations\CompareValidatorAdapter.cs">
<Link>CompareValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\CreditCardValidatorAdapter.cs">
<Link>CreditCardValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DefaultPropertyValidatorFactory.cs">
<Link>DefaultPropertyValidatorFactory.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\EmailAddressValidatorAdapter.cs">
<Link>EmailAddressValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\EnumDataTypeValidatorAdapter.cs">
<Link>EnumDataTypeValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\FileExtensionsValidatorAdapter.cs">
<Link>FileExtensionsValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\IPropertyValidator.cs">
<Link>IPropertyValidator.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\IPropertyValidatorFactory.cs">
<Link>IPropertyValidatorFactory.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\IValidatableObjectAdapter.cs">
<Link>IValidatableObjectAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\MaxLengthValidatorAdapter.cs">
<Link>MaxLengthValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\MinLengthValidatorAdapter.cs">
<Link>MinLengthValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\PhoneValidatorAdapter.cs">
<Link>PhoneValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\PropertyValidator.cs">
<Link>PropertyValidator.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DataAnnotationsRegistrations.cs">
<Link>DataAnnotationsRegistrations.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DefaultValidatableObjectAdapter.cs">
<Link>DefaultValidatableObjectAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DataAnnotationsValidator.cs">
<Link>DataAnnotationsValidator.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DataAnnotationsValidatorAdapter.cs">
<Link>DataAnnotationsValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\DataAnnotationsValidatorFactory.cs">
<Link>DataAnnotationsValidatorFactory.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\IDataAnnotationsValidatorAdapter.cs">
<Link>IDataAnnotationsValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\RangeValidatorAdapter.cs">
<Link>RangeValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\RegexValidatorAdapter.cs">
<Link>RegexValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\RequiredValidatorAdapter.cs">
<Link>RequiredValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\StringLengthValidatorAdapter.cs">
<Link>StringLengthValidatorAdapter.cs</Link>
</Compile>
<Compile Include="..\Nancy.Validation.DataAnnotations\UrlValidatorAdapter.cs">
<Link>UrlValidatorAdapter.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Nancy.Hosting.Self.MSBuild\Nancy.Hosting.Self.csproj">
Expand Down
60 changes: 14 additions & 46 deletions samples/Nancy.Demo.Validation/Nancy.Demo.Validation.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -11,14 +11,15 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Nancy.Demo.Validation</RootNamespace>
<AssemblyName>Nancy.Demo.Validation</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -41,39 +42,6 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MonoDebug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>bin\Nancy.Demo.Validation.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MonoRelease|AnyCPU'">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>bin\Nancy.Demo.Validation.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentValidation, Version=6.3.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\FluentValidation.6.3.4-alpha\lib\Net45\FluentValidation.dll</HintPath>
Expand Down Expand Up @@ -113,24 +81,24 @@
<Compile Include="ValidationBootstrapper.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Nancy.Hosting.Aspnet.MSBuild\Nancy.Hosting.Aspnet.csproj">
<Project>{15B7F794-0BB2-4B66-AD78-4A951F1209B2}</Project>
<ProjectReference Include="..\..\src\Nancy.Hosting.Aspnet\Nancy.Hosting.Aspnet.csproj">
<Project>{833a65bc-5b37-468d-8bb4-2343cefdfa5d}</Project>
<Name>Nancy.Hosting.Aspnet</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Nancy.Validation.DataAnnotations.MSBuild\Nancy.Validation.DataAnnotations.csproj">
<Project>{701765DC-F4F2-4943-A37F-6ED253198158}</Project>
<ProjectReference Include="..\..\src\Nancy.Validation.DataAnnotations\Nancy.Validation.DataAnnotations.csproj">
<Project>{fa2462fe-a439-48c5-976d-491f73c25ce1}</Project>
<Name>Nancy.Validation.DataAnnotations</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Nancy.Validation.FluentValidation.MSBuild\Nancy.Validation.FluentValidation.csproj">
<Project>{01230F2A-D108-480C-B834-8CE0569FD3B3}</Project>
<ProjectReference Include="..\..\src\Nancy.Validation.FluentValidation\Nancy.Validation.FluentValidation.csproj">
<Project>{33d5fb92-074e-4c13-bfd6-21184dd0013a}</Project>
<Name>Nancy.Validation.FluentValidation</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Nancy.ViewEngines.Spark.MSBuild\Nancy.ViewEngines.Spark.csproj">
<Project>{4B7E35DF-1569-4346-B180-A09615723095}</Project>
<ProjectReference Include="..\..\src\Nancy.ViewEngines.Spark\Nancy.ViewEngines.Spark.csproj">
<Project>{0e546413-bbf8-40b3-8534-8d1d986aa888}</Project>
<Name>Nancy.ViewEngines.Spark</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Nancy.MSBuild\Nancy.csproj">
<Project>{34576216-0DCA-4B0F-A0DC-9075E75A676F}</Project>
<ProjectReference Include="..\..\src\Nancy\Nancy.csproj">
<Project>{adab2c6b-10fe-4b31-bcd2-e2efa69d5a66}</Project>
<Name>Nancy</Name>
</ProjectReference>
</ItemGroup>
Expand Down Expand Up @@ -167,7 +135,7 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
Expand Down
3 changes: 1 addition & 2 deletions samples/Nancy.Demo.Validation/Web.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0"?>

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<compilation debug="true" targetFramework="4.5.2" />
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
Expand Down
67 changes: 67 additions & 0 deletions src/Nancy.Validation.DataAnnotations/CompareValidatorAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace Nancy.Validation.DataAnnotations
{
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Nancy.Validation.Rules;

/// <summary>
/// An adapter for the <see cref="CompareAttribute"/>.
/// </summary>
public class CompareValidatorAdapter : DataAnnotationsValidatorAdapter
{
/// <summary>
/// Initializes a new instance of the <see cref="CompareValidatorAdapter"/> class.
/// </summary>
public CompareValidatorAdapter()
: base("Compare")
{
}

/// <summary>
/// Gets a boolean that indicates if the adapter can handle the
/// provided <paramref name="attribute"/>.
/// </summary>
/// <param name="attribute">The <see cref="ValidationAttribute"/> that should be handled.</param>
/// <returns><see langword="true" /> if the attribute can be handles, otherwise <see langword="false" />.</returns>
public override bool CanHandle(ValidationAttribute attribute)
{
return attribute is CompareAttribute;
}

/// <summary>
/// Gets the rules the adapter provides.
/// </summary>
/// <param name="attribute">The <see cref="ValidationAttribute"/> that should be handled.</param>
/// <param name="descriptor">A <see cref="PropertyDescriptor"/> instance for the property that is being validated.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public override IEnumerable<ModelValidationRule> GetRules(ValidationAttribute attribute, PropertyDescriptor descriptor)
{
var compareAttribute = (CompareAttribute)attribute;

yield return new ComparisonValidationRule(attribute.FormatErrorMessage,
new[] { descriptor.Name },
ComparisonOperator.Equal,
compareAttribute.OtherProperty);
}

/// <summary>
/// Gets a <see cref="ModelValidationError"/> instance based on the supplied <see cref="ValidationResult"/>.
/// </summary>
/// <param name="result">The <see cref="ValidationResult"/> to create a <see cref="ModelValidationError"/> for.</param>
/// <param name="context">The <see cref="ValidationContext"/> of the supplied <see cref="ValidationResult"/>.</param>
/// <param name="attribute">The <see cref="ValidationAttribute"/> being validated.</param>
/// <returns>A <see cref="ModelValidationError"/> of member names.</returns>
protected override ModelValidationError GetValidationError(ValidationResult result, ValidationContext context, ValidationAttribute attribute)
{
var compareAttribute = (CompareAttribute)attribute;

// member names are NOT returned from GetValidationResult like they are with other validation attributes
return new ModelValidationError(new[]
{
context.MemberName,
compareAttribute.OtherProperty
}, result.ErrorMessage);
}
}
}
Loading