Create ObjectExtensionPropertyInfoValidationExtensions.

pull/3561/head
Halil İbrahim Kalkan 5 years ago
parent e26e7ab48d
commit 85f1fc5496

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
namespace Volo.Abp.ObjectExtending
{
public static class ObjectExtensionPropertyInfoValidationExtensions
{
public const string ValidationConfigurationName = "Validation";
[NotNull]
public static ObjectExtensionPropertyInfo ConfigureValidation(
[NotNull] this ObjectExtensionPropertyInfo propertyExtension,
[NotNull] Action<ObjectExtensionPropertyInfoValidationOptions> configureAction)
{
Check.NotNull(propertyExtension, nameof(propertyExtension));
Check.NotNull(configureAction, nameof(configureAction));
configureAction(propertyExtension.GetOrAddValidationConfiguration());
return propertyExtension;
}
[NotNull]
public static ObjectExtensionPropertyInfo AddValidationAttributes(
[NotNull] this ObjectExtensionPropertyInfo propertyExtension,
[NotNull] params ValidationAttribute[] validationAttributes)
{
Check.NotNull(propertyExtension, nameof(propertyExtension));
Check.NotNullOrEmpty(validationAttributes, nameof(validationAttributes));
propertyExtension
.GetOrAddValidationConfiguration()
.ValidationAttributes
.AddRange(validationAttributes);
return propertyExtension;
}
[CanBeNull]
public static ObjectExtensionPropertyInfoValidationOptions GetValidationConfigurationOrNull(
[NotNull] this ObjectExtensionPropertyInfo propertyExtension)
{
Check.NotNull(propertyExtension, nameof(propertyExtension));
return propertyExtension.Configuration.GetOrDefault(ValidationConfigurationName)
as ObjectExtensionPropertyInfoValidationOptions;
}
[NotNull]
public static ObjectExtensionPropertyInfoValidationOptions GetOrAddValidationConfiguration(
[NotNull] this ObjectExtensionPropertyInfo propertyExtension)
{
Check.NotNull(propertyExtension, nameof(propertyExtension));
var validationConfiguration = propertyExtension.GetValidationConfigurationOrNull();
if (validationConfiguration == null)
{
validationConfiguration = new ObjectExtensionPropertyInfoValidationOptions(propertyExtension);
propertyExtension.Configuration[ValidationConfigurationName] = validationConfiguration;
}
return validationConfiguration;
}
}
}

@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;
namespace Volo.Abp.ObjectExtending
{
public class ObjectExtensionPropertyInfoValidationOptions
{
[NotNull]
public ObjectExtensionPropertyInfo ExtensionProperty { get; }
[NotNull]
public ObjectExtensionInfo ObjectExtension => ExtensionProperty.ObjectExtension;
[NotNull]
public List<ValidationAttribute> ValidationAttributes { get; }
public ObjectExtensionPropertyInfoValidationOptions(
[NotNull] ObjectExtensionPropertyInfo extensionProperty)
{
ExtensionProperty = Check.NotNull(extensionProperty, nameof(extensionProperty));
ValidationAttributes = new List<ValidationAttribute>();
}
}
}

@ -18,6 +18,7 @@ namespace Volo.Abp.Validation
context.Services.OnRegistred(ValidationInterceptorRegistrar.RegisterIfNeeded);
AutoAddObjectValidationContributors(context.Services);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>

Loading…
Cancel
Save