mirror of https://github.com/abpframework/abp.git
99 changed files with 767 additions and 250 deletions
@ -0,0 +1,46 @@ |
|||||
|
using System.Globalization; |
||||
|
using Microsoft.AspNetCore.Mvc.DataAnnotations; |
||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Volo.Abp.Validation; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.DataAnnotations |
||||
|
{ |
||||
|
public class DynamicMaxLengthAttributeAdapter : AttributeAdapterBase<DynamicMaxLengthAttribute> |
||||
|
{ |
||||
|
private readonly string _max; |
||||
|
|
||||
|
public DynamicMaxLengthAttributeAdapter( |
||||
|
DynamicMaxLengthAttribute attribute, |
||||
|
IStringLocalizer stringLocalizer) |
||||
|
: base(attribute, stringLocalizer) |
||||
|
{ |
||||
|
_max = Attribute.Length.ToString(CultureInfo.InvariantCulture); |
||||
|
} |
||||
|
|
||||
|
public override string GetErrorMessage(ModelValidationContextBase validationContext) |
||||
|
{ |
||||
|
Check.NotNull(validationContext, nameof(validationContext)); |
||||
|
|
||||
|
return GetErrorMessage( |
||||
|
validationContext.ModelMetadata, |
||||
|
validationContext.ModelMetadata.GetDisplayName(), |
||||
|
Attribute.Length |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public override void AddValidation(ClientModelValidationContext context) |
||||
|
{ |
||||
|
Check.NotNull(context, nameof(context)); |
||||
|
|
||||
|
MergeAttribute(context.Attributes, "data-val", "true"); |
||||
|
MergeAttribute(context.Attributes, "data-val-maxlength", GetErrorMessage(context)); |
||||
|
MergeAttribute(context.Attributes, "data-val-maxlength-max", _max); |
||||
|
|
||||
|
if (Attribute.Length != int.MaxValue) |
||||
|
{ |
||||
|
MergeAttribute(context.Attributes, "data-val-maxlength-max", _max); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.Diagnostics; |
||||
|
using System.Reflection; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Validation |
||||
|
{ |
||||
|
public class DynamicMaxLengthAttribute : MaxLengthAttribute |
||||
|
{ |
||||
|
private static readonly FieldInfo MaximumLengthField; |
||||
|
|
||||
|
static DynamicMaxLengthAttribute() |
||||
|
{ |
||||
|
MaximumLengthField = typeof(MaxLengthAttribute).GetField( |
||||
|
"<Length>k__BackingField", |
||||
|
BindingFlags.Instance | BindingFlags.NonPublic |
||||
|
); |
||||
|
Debug.Assert(MaximumLengthField != null, nameof(MaximumLengthField) + " != null"); |
||||
|
} |
||||
|
|
||||
|
public DynamicMaxLengthAttribute( |
||||
|
[NotNull] Type sourceType, |
||||
|
[CanBeNull] string maximumLengthPropertyName) |
||||
|
{ |
||||
|
Check.NotNull(sourceType, nameof(sourceType)); |
||||
|
|
||||
|
if (maximumLengthPropertyName != null) |
||||
|
{ |
||||
|
var maximumLengthProperty = sourceType.GetProperty( |
||||
|
maximumLengthPropertyName, |
||||
|
BindingFlags.Static | BindingFlags.Public |
||||
|
); |
||||
|
Debug.Assert(maximumLengthProperty != null, nameof(maximumLengthProperty) + " != null"); |
||||
|
MaximumLengthField.SetValue(this, (int) maximumLengthProperty.GetValue(null)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,12 +1,13 @@ |
|||||
using System.ComponentModel.DataAnnotations; |
using System.ComponentModel.DataAnnotations; |
||||
using Volo.Abp.ObjectExtending; |
using Volo.Abp.ObjectExtending; |
||||
|
using Volo.Abp.Validation; |
||||
|
|
||||
namespace Volo.Abp.TenantManagement |
namespace Volo.Abp.TenantManagement |
||||
{ |
{ |
||||
public abstract class TenantCreateOrUpdateDtoBase : ExtensibleObject |
public abstract class TenantCreateOrUpdateDtoBase : ExtensibleObject |
||||
{ |
{ |
||||
[Required] |
[Required] |
||||
[StringLength(TenantConsts.MaxNameLength)] |
[DynamicStringLength(typeof(TenantConsts), nameof(TenantConsts.MaxNameLength))] |
||||
public string Name { get; set; } |
public string Name { get; set; } |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
const glob = require('glob'); |
||||
|
const fse = require('fs-extra'); |
||||
|
|
||||
|
function replace(filePath) { |
||||
|
const pkg = fse.readJsonSync(filePath); |
||||
|
|
||||
|
const { dependencies } = pkg; |
||||
|
|
||||
|
if (!dependencies) return; |
||||
|
|
||||
|
Object.keys(dependencies).forEach((key) => { |
||||
|
if (key.includes('@abp/') && key !== '@abp/utils') { |
||||
|
dependencies[key] = dependencies[key].replace('^', '~'); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
fse.writeJsonSync(filePath, { ...pkg, dependencies }, { spaces: 2 }); |
||||
|
} |
||||
|
|
||||
|
glob('./packs/**/package.json', {}, (er, files) => { |
||||
|
files.forEach((path) => { |
||||
|
if (path.includes('node_modules')) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
replace(path); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue