Merge pull request #382 from varKeytrap/master

Added Custom support for TextType
This commit is contained in:
NaBian 2020-07-12 00:10:32 +08:00 committed by GitHub
commit 6c61113757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 23 deletions

View File

@ -68,5 +68,17 @@ namespace HandyControl.Controls
public static double GetMaxContentHeight(DependencyObject element)
=> (double) element.GetValue(MaxContentHeightProperty);
/// <summary>
/// 正则表达式
/// </summary>
public static readonly DependencyProperty RegexPatternProperty = DependencyProperty.RegisterAttached(
"RegexPattern", typeof(string), typeof(InfoElement), new PropertyMetadata(default(string)));
public static void SetRegexPattern(DependencyObject element, string value)
=> element.SetValue(RegexPatternProperty, value);
public static string GetRegexPattern(DependencyObject element)
=> (string) element.GetValue(RegexPatternProperty);
}
}

View File

@ -46,7 +46,7 @@ namespace HandyControl.Controls
public string ErrorStr
{
get => (string) GetValue(ErrorStrProperty);
get => (string)GetValue(ErrorStrProperty);
set => SetValue(ErrorStrProperty, value);
}
@ -58,7 +58,7 @@ namespace HandyControl.Controls
public TextType TextType
{
get => (TextType) GetValue(TextTypeProperty);
get => (TextType)GetValue(TextTypeProperty);
set => SetValue(TextTypeProperty, value);
}
@ -88,7 +88,14 @@ namespace HandyControl.Controls
{
if (TextType != TextType.Common)
{
result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError);
var regexPattern = InfoElement.GetRegexPattern(this);
result = string.IsNullOrEmpty(regexPattern)
? Text.IsKindOf(TextType)
? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError)
: Text.IsKindOf(regexPattern)
? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError);
}
else
{

View File

@ -22,6 +22,6 @@ namespace HandyControl.Data
NDouble,
Double,
NnDouble,
NpDouble,
NpDouble
}
}

View File

@ -376,8 +376,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegexJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegexPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ButtonGroupItemStyleSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ComboBoxItemCapsuleStyleSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\TabItemCapsuleStyleSelector.cs" />

View File

@ -79,7 +79,7 @@ namespace HandyControl.Media.Animation
{
var geometryStr = defaultDestinationValue.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out _numbersTo);
_strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern);
_strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
}
UpdateValue();
@ -150,7 +150,7 @@ namespace HandyControl.Media.Animation
{
var geometryStr = geometry.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out obj._numbersTo);
obj._strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern);
obj._strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
obj.UpdateValue();
}
}

View File

@ -27,7 +27,7 @@ namespace HandyControl.Media.Animation
return null;
}
return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegularPatterns.DigitsPattern);
return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegexPatterns.DigitsPattern);
}
}

View File

@ -43,7 +43,7 @@ namespace HandyControl.Tools
internal static void DecomposeGeometryStr(string geometryStr, out double[] arr)
{
var collection = Regex.Matches(geometryStr, RegularPatterns.DigitsPattern);
var collection = Regex.Matches(geometryStr, RegexPatterns.DigitsPattern);
arr = new double[collection.Count];
for (var i = 0; i < collection.Count; i++)
{

View File

@ -7,9 +7,9 @@ namespace HandyControl.Tools
/// <summary>
/// 包含一些正则验证操作
/// </summary>
public static class RegularJudgment
public static class RegexJudgment
{
private static readonly RegularPatterns RegularPatterns = new RegularPatterns();
private static readonly RegexPatterns RegexPatterns = new RegexPatterns();
/// <summary>
/// 判断字符串格式是否符合某种要求
@ -32,7 +32,7 @@ namespace HandyControl.Tools
{
if (textType == TextType.Common) return true;
return Regex.IsMatch(text,
RegularPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString());
RegexPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString());
}
/// <summary>
@ -42,7 +42,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns>
public static bool IsEmail(this string email)
{
return Regex.IsMatch(email, RegularPatterns.MailPattern);
return Regex.IsMatch(email, RegexPatterns.MailPattern);
}
/// <summary>
@ -55,11 +55,11 @@ namespace HandyControl.Tools
{
switch (ipType)
{
case IpType.A: return Regex.IsMatch(ip, RegularPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegularPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegularPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegularPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegularPatterns.IpEPattern);
case IpType.A: return Regex.IsMatch(ip, RegexPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegexPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegexPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegexPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegexPatterns.IpEPattern);
default: return false;
}
}
@ -71,7 +71,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns>
public static bool IsIp(this string ip)
{
return Regex.IsMatch(ip, RegularPatterns.IpPattern);
return Regex.IsMatch(ip, RegexPatterns.IpPattern);
}
/// <summary>
@ -81,7 +81,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns>
public static bool IsChinese(this string str)
{
return Regex.IsMatch(str, RegularPatterns.ChinesePattern);
return Regex.IsMatch(str, RegexPatterns.ChinesePattern);
}
/// <summary>
@ -91,7 +91,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns>
public static bool IsUrl(this string str)
{
return Regex.IsMatch(str, RegularPatterns.UrlPattern);
return Regex.IsMatch(str, RegexPatterns.UrlPattern);
}
}
}

View File

@ -3,7 +3,7 @@
/// <summary>
/// 包含一些正则验证所需要的字符串
/// </summary>
public sealed class RegularPatterns
public sealed class RegexPatterns
{
/// <summary>
/// 邮件正则匹配表达式