mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-05-10 23:42:56 +12:00
SizeConverter : update regex value to allow negative values
This commit is contained in:
parent
f59db2c01e
commit
63e9487423
|
@ -10,7 +10,7 @@ namespace OnTopReplica.StartupOptions {
|
||||||
class SizeConverter : TypeConverter {
|
class SizeConverter : TypeConverter {
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
|
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
|
||||||
if (value != null) {
|
if(value != null) {
|
||||||
var sVal = value.ToString();
|
var sVal = value.ToString();
|
||||||
return StringToSize(sVal);
|
return StringToSize(sVal);
|
||||||
}
|
}
|
||||||
|
@ -27,26 +27,26 @@ namespace OnTopReplica.StartupOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
|
||||||
if (value == null)
|
if(value == null)
|
||||||
return base.ConvertTo(context, culture, value, destinationType);
|
return base.ConvertTo(context, culture, value, destinationType);
|
||||||
|
|
||||||
if (destinationType == typeof(Size)) {
|
if(destinationType == typeof(Size)) {
|
||||||
var sVal = value.ToString();
|
var sVal = value.ToString();
|
||||||
return StringToSize(sVal);
|
return StringToSize(sVal);
|
||||||
}
|
}
|
||||||
else if (destinationType == typeof(string)) {
|
else if(destinationType == typeof(string)) {
|
||||||
if (value is Size) {
|
if(value is Size) {
|
||||||
Size sValue = (Size)value;
|
Size sValue = (Size)value;
|
||||||
return string.Format("{0}, {1}", sValue.Width, sValue.Height);
|
return string.Format("{0}, {1}", sValue.Width, sValue.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.ToString();
|
return value.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return base.ConvertTo(context, culture, value, destinationType);
|
return base.ConvertTo(context, culture, value, destinationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Regex _sizeRegex = new Regex("^\\D*(?<x>\\d*)\\s*,\\s*(?<y>\\d*)\\D*$",
|
static Regex _sizeRegex = new Regex("^[^0-9-]*(?<x>-?\\d*)\\s*,\\s*(?<y>-?\\d*)\\D*$",
|
||||||
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);
|
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);
|
||||||
|
|
||||||
private Size StringToSize(string s) {
|
private Size StringToSize(string s) {
|
||||||
|
@ -55,7 +55,7 @@ namespace OnTopReplica.StartupOptions {
|
||||||
var x = match.Groups["x"];
|
var x = match.Groups["x"];
|
||||||
var y = match.Groups["y"];
|
var y = match.Groups["y"];
|
||||||
|
|
||||||
if (!match.Success || !x.Success || !y.Success)
|
if(!match.Success || !x.Success || !y.Success)
|
||||||
throw new ArgumentException("Cannot convert '" + s + "' to coordinates pair.");
|
throw new ArgumentException("Cannot convert '" + s + "' to coordinates pair.");
|
||||||
|
|
||||||
var xVal = Int32.Parse(x.Value);
|
var xVal = Int32.Parse(x.Value);
|
||||||
|
|
Loading…
Reference in a new issue