Parse string:
public static Size Parse(this string str) ...
, , URL WxH, . 1024x768:
namespace MySize
{
public static class Extensions
{
public static Size Parse(this string str)
{
try {
var a = str.Split(new char[] { 'x' });
return new Size() {
Width = int.Parse(a[0]),
Height = int.Parse(a[1])
};
}
catch(Exception) { }
return Size.nosize;
}
}
public class Size
{
public int Width { get; set; }
public int Height { get; set; }
public override string ToString()
{
return Width.ToString() + "x" + Height.ToString();
}
public Size(System.Drawing.Size from)
{
Width = from.Width;
Height = from.Height;
}
public Size()
{
}
public static Size nosize = new Size(new System.Drawing.Size(-1, -1));
}
}
ToString() Parse ( String). :
[TestMethod]
public void TestSizeParse()
{
var s1 = new Size(1024, 768);
var s1Str = s1.ToString();
Size s2 = s1Str.Parse();
Assert.AreEqual(s1.Width, s2.Width);
Assert.AreEqual(s1.Height, s2.Height);
Assert.AreEqual(s1, s2, "s1 and s2 are supposed to be equal");
}