😎代码优化
This commit is contained in:
parent
fd12e5b74b
commit
5b82f75f04
@ -34,8 +34,9 @@ public class DataMaskAttribute : Attribute
|
|||||||
|
|
||||||
public DataMaskAttribute(int startIndex, int length)
|
public DataMaskAttribute(int startIndex, int length)
|
||||||
{
|
{
|
||||||
if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex));
|
ArgumentOutOfRangeException.ThrowIfNegative(startIndex);
|
||||||
if (length <= 0) throw new ArgumentOutOfRangeException(nameof(length));
|
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(length);
|
||||||
|
|
||||||
StartIndex = startIndex;
|
StartIndex = startIndex;
|
||||||
Length = length;
|
Length = length;
|
||||||
@ -52,8 +53,6 @@ public class DataMaskAttribute : Attribute
|
|||||||
var maskedLength = Math.Min(Length, input.Length - StartIndex);
|
var maskedLength = Math.Min(Length, input.Length - StartIndex);
|
||||||
var maskStr = new string(MaskChar, KeepLength ? maskedLength : Math.Min(4, maskedLength));
|
var maskStr = new string(MaskChar, KeepLength ? maskedLength : Math.Min(4, maskedLength));
|
||||||
|
|
||||||
return input.Substring(0, StartIndex) + maskStr +
|
return input.Substring(0, StartIndex) + maskStr + (StartIndex + maskedLength < input.Length ? input.Substring(StartIndex + maskedLength) : "");
|
||||||
(StartIndex + maskedLength < input.Length ?
|
|
||||||
input.Substring(StartIndex + maskedLength) : "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ public static class SqlSugarPagedExtensions
|
|||||||
{
|
{
|
||||||
RefAsync<int> total = 0;
|
RefAsync<int> total = 0;
|
||||||
var items = await query.ToPageListAsync(pageIndex, pageSize, total);
|
var items = await query.ToPageListAsync(pageIndex, pageSize, total);
|
||||||
items.ForEach(x => x.MaskSensitiveData());
|
items.ForEach(u => u.MaskSensitiveData());
|
||||||
return CreateSqlSugarPagedList(items, total, pageIndex, pageSize);
|
return CreateSqlSugarPagedList(items, total, pageIndex, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ public static class SqlSugarPagedExtensions
|
|||||||
{
|
{
|
||||||
var total = list.Count();
|
var total = list.Count();
|
||||||
var items = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
var items = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||||
items.ForEach(x => x.MaskSensitiveData());
|
items.ForEach(u => u.MaskSensitiveData());
|
||||||
return CreateSqlSugarPagedList(items, total, pageIndex, pageSize);
|
return CreateSqlSugarPagedList(items, total, pageIndex, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user