From 1679041211bd06a33d2b1826c729ed7c2e1833e6 Mon Sep 17 00:00:00 2001 From: donandren Date: Mon, 9 May 2016 15:34:58 +0300 Subject: [PATCH] added Size.Parse --- src/Perspex.SceneGraph/Size.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Perspex.SceneGraph/Size.cs b/src/Perspex.SceneGraph/Size.cs index 1e7acc0096..83b49fc0da 100644 --- a/src/Perspex.SceneGraph/Size.cs +++ b/src/Perspex.SceneGraph/Size.cs @@ -128,6 +128,28 @@ namespace Perspex return new Size(size._width - toSubstract._width, size._height - toSubstract._height); } + /// + /// Parses a string. + /// + /// The string. + /// The current culture. + /// The . + 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."); + } + } + /// /// Constrains the size. ///