From: Jean-Philippe Bruyère Date: Wed, 20 Jan 2021 19:56:20 +0000 (+0100) Subject: Typed static Parse instead of returning object X-Git-Tag: v0.9.5-beta~93 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4714088d9cbaba81451a899cd97390f133b6a3cf;p=jp%2Fcrow.git Typed static Parse instead of returning object --- diff --git a/Crow/src/Colors.cs b/Crow/src/Colors.cs index eb62cb14..5b4396f7 100644 --- a/Crow/src/Colors.cs +++ b/Crow/src/Colors.cs @@ -350,7 +350,7 @@ namespace Crow return new Color (components); } - public static object Parse(string s) + public static Color Parse(string s) => string.IsNullOrEmpty (s) ? new Color (Colors.White) : s[0] == '#' ? new Color (UInt32.Parse (s.AsSpan().Slice (1), System.Globalization.NumberStyles.HexNumber)) : char.IsDigit(s[0]) ? FromIml (s) : diff --git a/Crow/src/Fill/Fill.cs b/Crow/src/Fill/Fill.cs index 24c94dca..a11b666e 100644 --- a/Crow/src/Fill/Fill.cs +++ b/Crow/src/Fill/Fill.cs @@ -18,12 +18,12 @@ namespace Crow /// backend context /// paint operation bounding box, unused for SolidColor public abstract void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle)); - public static object Parse (string s){ + public static Fill Parse (string s){ ReadOnlySpan tmp = s.AsSpan (); if (tmp.Length == 0) return null; if (tmp.Length > 8 && tmp.Slice (1, 8).SequenceEqual ("gradient")) - return Gradient.Parse (s); + return (Fill)Gradient.Parse (s); if (tmp.EndsWith (".svg", StringComparison.OrdinalIgnoreCase) || tmp.EndsWith (".png", StringComparison.OrdinalIgnoreCase) || tmp.EndsWith (".jpg", StringComparison.OrdinalIgnoreCase) || diff --git a/Crow/src/Fill/Picture.cs b/Crow/src/Fill/Picture.cs index fd86506a..c9b23404 100644 --- a/Crow/src/Fill/Picture.cs +++ b/Crow/src/Fill/Picture.cs @@ -100,7 +100,7 @@ namespace Crow public static implicit operator string(Picture _pic) => _pic == null ? null : _pic.Path; #endregion - public static new object Parse(string path) + public static new Picture Parse(string path) { if (string.IsNullOrEmpty (path)) return null; diff --git a/Crow/src/Font.cs b/Crow/src/Font.cs index c326b4ea..f05c6fb1 100644 --- a/Crow/src/Font.cs +++ b/Crow/src/Font.cs @@ -70,7 +70,7 @@ namespace Crow public override string ToString () => _style == FontStyle.Normal ? $"{_name},{_size}" : $"{_name} {_style},{_size}"; - public static object Parse(string s) + public static Font Parse(string s) { Font f = new Font (); ReadOnlySpan tmp = s.AsSpan ().Trim ();