Browse Source

added Size.Parse

pull/531/head
donandren 11 years ago
parent
commit
1679041211
  1. 22
      src/Perspex.SceneGraph/Size.cs

22
src/Perspex.SceneGraph/Size.cs

@ -128,6 +128,28 @@ namespace Perspex
return new Size(size._width - toSubstract._width, size._height - toSubstract._height);
}
/// <summary>
/// Parses a <see cref="Size"/> string.
/// </summary>
/// <param name="s">The string.</param>
/// <param name="culture">The current culture.</param>
/// <returns>The <see cref="Size"/>.</returns>
public static Size Parse(string s, CultureInfo culture)
{
var parts = s.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.ToList();
if (parts.Count == 2)
{
return new Size(double.Parse(parts[0], culture), double.Parse(parts[1], culture));
}
else
{
throw new FormatException("Invalid Size.");
}
}
/// <summary>
/// Constrains the size.
/// </summary>

Loading…
Cancel
Save