-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10732 from abpframework/maliming/IValueValidatorF…
…actory Add `IValueValidatorFactory`
- Loading branch information
Showing
12 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...n.Contracts/Volo/Abp/FeatureManagement/AbpFeatureManagementApplicationContractsOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using Volo.Abp.FeatureManagement.JsonConverters; | ||
using Volo.Abp.Validation.StringValues; | ||
|
||
namespace Volo.Abp.FeatureManagement; | ||
|
||
public class AbpFeatureManagementApplicationContractsOptions | ||
{ | ||
public HashSet<IValueValidatorFactory> ValueValidatorFactory { get; } | ||
|
||
public AbpFeatureManagementApplicationContractsOptions() | ||
{ | ||
ValueValidatorFactory = new HashSet<IValueValidatorFactory> | ||
{ | ||
new ValueValidatorFactory<AlwaysValidValueValidator>("NULL"), | ||
new ValueValidatorFactory<BooleanValueValidator>("BOOLEAN"), | ||
new ValueValidatorFactory<NumericValueValidator>("NUMERIC"), | ||
new ValueValidatorFactory<StringValueValidator>("STRING") | ||
}; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/IValueValidatorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Volo.Abp.Validation.StringValues; | ||
|
||
namespace Volo.Abp.FeatureManagement.JsonConverters; | ||
|
||
public interface IValueValidatorFactory | ||
{ | ||
bool CanCreate(string name); | ||
|
||
IValueValidator Create(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
....Application.Contracts/Volo/Abp/FeatureManagement/JsonConverters/ValueValidatorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Volo.Abp.Validation.StringValues; | ||
|
||
namespace Volo.Abp.FeatureManagement.JsonConverters; | ||
|
||
public class ValueValidatorFactory<TValueValidator> : IValueValidatorFactory | ||
where TValueValidator : IValueValidator, new() | ||
{ | ||
protected readonly string Name; | ||
|
||
public ValueValidatorFactory(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public bool CanCreate(string name) | ||
{ | ||
return Name == name; | ||
} | ||
|
||
public IValueValidator Create() | ||
{ | ||
return new TValueValidator() as IValueValidator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...o.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/UrlValueValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Volo.Abp.Validation.StringValues; | ||
|
||
namespace Volo.Abp.FeatureManagement; | ||
|
||
[Serializable] | ||
[ValueValidator("URL")] | ||
public class UrlValueValidator : ValueValidatorBase | ||
{ | ||
public string Scheme { | ||
get => this["Scheme"].ToString(); | ||
set => this["Scheme"] = value; | ||
} | ||
|
||
public UrlValueValidator() | ||
{ | ||
|
||
} | ||
|
||
public UrlValueValidator(string scheme) | ||
{ | ||
Scheme = scheme; | ||
} | ||
|
||
public override bool IsValid(object value) | ||
{ | ||
var s = value.ToString(); | ||
return s != null && s.StartsWith(Scheme); | ||
} | ||
} |