merged pr

This commit is contained in:
NaBian committed 2020-07-12 00:07:14 +08:00
1 parent e8ecb7d6be
commit 62b1eb2473
9 files changed
+44 -40

No files matched your search

@@ -68,5 +68,17 @@ namespace HandyControl.Controls
public static double GetMaxContentHeight(DependencyObject element) public static double GetMaxContentHeight(DependencyObject element)
=> (double) element.GetValue(MaxContentHeightProperty); => (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);
} }
} }
@@ -1,5 +1,4 @@
using System; using System;
using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@@ -36,7 +35,7 @@ namespace HandyControl.Controls
public bool IsError public bool IsError
{ {
get => (bool) GetValue(IsErrorProperty); get => (bool)GetValue(IsErrorProperty);
set => SetValue(IsErrorProperty, value); set => SetValue(IsErrorProperty, value);
} }
@@ -48,7 +47,7 @@ namespace HandyControl.Controls
public string ErrorStr public string ErrorStr
{ {
get => (string) GetValue(ErrorStrProperty); get => (string)GetValue(ErrorStrProperty);
set => SetValue(ErrorStrProperty, value); set => SetValue(ErrorStrProperty, value);
} }
@@ -60,7 +59,7 @@ namespace HandyControl.Controls
public TextType TextType public TextType TextType
{ {
get => (TextType) GetValue(TextTypeProperty); get => (TextType)GetValue(TextTypeProperty);
set => SetValue(TextTypeProperty, value); set => SetValue(TextTypeProperty, value);
} }
@@ -72,20 +71,10 @@ namespace HandyControl.Controls
public bool ShowClearButton public bool ShowClearButton
{ {
get => (bool) GetValue(ShowClearButtonProperty); get => (bool)GetValue(ShowClearButtonProperty);
set => SetValue(ShowClearButtonProperty, value); set => SetValue(ShowClearButtonProperty, value);
} }
public static readonly DependencyProperty TextTypeCustomRegexPatternProperty = DependencyProperty.Register(
"TextTypeCustomRegexPattern", typeof(string), typeof(TextBox), new PropertyMetadata(null));
public string TextTypeCustomRegexPattern
{
get => (string)GetValue(TextTypeCustomRegexPatternProperty);
set => SetValue(TextTypeCustomRegexPatternProperty, value);
}
public virtual bool VerifyData() public virtual bool VerifyData()
{ {
OperationResult<bool> result; OperationResult<bool> result;
@@ -100,10 +89,14 @@ namespace HandyControl.Controls
{ {
if (TextType != TextType.Common) if (TextType != TextType.Common)
{ {
if (TextType == TextType.Custom && !string.IsNullOrEmpty(TextTypeCustomRegexPattern)) var regexPattern = InfoElement.GetRegexPattern(this);
result = Regex.IsMatch(Text, TextTypeCustomRegexPattern) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); result = string.IsNullOrEmpty(regexPattern)
else ? Text.IsKindOf(TextType)
result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); ? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError)
: Text.IsKindOf(regexPattern)
? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError);
} }
else else
{ {
@@ -22,7 +22,6 @@ namespace HandyControl.Data
NDouble, NDouble,
Double, Double,
NnDouble, NnDouble,
NpDouble, NpDouble
Custom
} }
} }
@@ -349,8 +349,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\RegexJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\RegexPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ButtonGroupItemStyleSelector.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ButtonGroupItemStyleSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\TabItemCapsuleStyleSelector.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\TabItemCapsuleStyleSelector.cs" />
</ItemGroup> </ItemGroup>
@@ -79,7 +79,7 @@ namespace HandyControl.Media.Animation
{ {
var geometryStr = defaultDestinationValue.ToString(CultureInfo.InvariantCulture); var geometryStr = defaultDestinationValue.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out _numbersTo); AnimationHelper.DecomposeGeometryStr(geometryStr, out _numbersTo);
_strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern); _strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
} }
UpdateValue(); UpdateValue();
@@ -150,7 +150,7 @@ namespace HandyControl.Media.Animation
{ {
var geometryStr = geometry.ToString(CultureInfo.InvariantCulture); var geometryStr = geometry.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out obj._numbersTo); AnimationHelper.DecomposeGeometryStr(geometryStr, out obj._numbersTo);
obj._strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern); obj._strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
obj.UpdateValue(); obj.UpdateValue();
} }
} }
@@ -27,7 +27,7 @@ namespace HandyControl.Media.Animation
return null; 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);
} }
} }
@@ -43,7 +43,7 @@ namespace HandyControl.Tools
internal static void DecomposeGeometryStr(string geometryStr, out double[] arr) 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]; arr = new double[collection.Count];
for (var i = 0; i < collection.Count; i++) for (var i = 0; i < collection.Count; i++)
{ {
@@ -7,9 +7,9 @@ namespace HandyControl.Tools
/// <summary> /// <summary>
/// 包含一些正则验证操作 /// 包含一些正则验证操作
/// </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> /// <summary>
/// 判断字符串格式是否符合某种要求 /// 判断字符串格式是否符合某种要求
@@ -32,7 +32,7 @@ namespace HandyControl.Tools
{ {
if (textType == TextType.Common) return true; if (textType == TextType.Common) return true;
return Regex.IsMatch(text, return Regex.IsMatch(text,
RegularPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString()); RegexPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString());
} }
/// <summary> /// <summary>
@@ -42,7 +42,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns> /// <returns>方法返回布尔值</returns>
public static bool IsEmail(this string email) public static bool IsEmail(this string email)
{ {
return Regex.IsMatch(email, RegularPatterns.MailPattern); return Regex.IsMatch(email, RegexPatterns.MailPattern);
} }
/// <summary> /// <summary>
@@ -55,11 +55,11 @@ namespace HandyControl.Tools
{ {
switch (ipType) switch (ipType)
{ {
case IpType.A: return Regex.IsMatch(ip, RegularPatterns.IpAPattern); case IpType.A: return Regex.IsMatch(ip, RegexPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegularPatterns.IpBPattern); case IpType.B: return Regex.IsMatch(ip, RegexPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegularPatterns.IpCPattern); case IpType.C: return Regex.IsMatch(ip, RegexPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegularPatterns.IpDPattern); case IpType.D: return Regex.IsMatch(ip, RegexPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegularPatterns.IpEPattern); case IpType.E: return Regex.IsMatch(ip, RegexPatterns.IpEPattern);
default: return false; default: return false;
} }
} }
@@ -71,7 +71,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns> /// <returns>方法返回布尔值</returns>
public static bool IsIp(this string ip) public static bool IsIp(this string ip)
{ {
return Regex.IsMatch(ip, RegularPatterns.IpPattern); return Regex.IsMatch(ip, RegexPatterns.IpPattern);
} }
/// <summary> /// <summary>
@@ -81,7 +81,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns> /// <returns>方法返回布尔值</returns>
public static bool IsChinese(this string str) public static bool IsChinese(this string str)
{ {
return Regex.IsMatch(str, RegularPatterns.ChinesePattern); return Regex.IsMatch(str, RegexPatterns.ChinesePattern);
} }
/// <summary> /// <summary>
@@ -91,7 +91,7 @@ namespace HandyControl.Tools
/// <returns>方法返回布尔值</returns> /// <returns>方法返回布尔值</returns>
public static bool IsUrl(this string str) public static bool IsUrl(this string str)
{ {
return Regex.IsMatch(str, RegularPatterns.UrlPattern); return Regex.IsMatch(str, RegexPatterns.UrlPattern);
} }
} }
} }
@@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// 包含一些正则验证所需要的字符串 /// 包含一些正则验证所需要的字符串
/// </summary> /// </summary>
public sealed class RegularPatterns public sealed class RegexPatterns
{ {
/// <summary> /// <summary>
/// 邮件正则匹配表达式 /// 邮件正则匹配表达式