diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index 487dcfb..9a5e173 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using Spectre.Console.Internal; namespace Spectre.Console @@ -47,16 +48,6 @@ namespace Spectre.Console Decoration = decoration ?? Decoration.None; } - /// - /// Converts the string representation of a style to its equivalent. - /// - /// A string containing a style to parse. - /// A equivalent of the text contained in . - public static Style Parse(string text) - { - return StyleParser.Parse(text); - } - /// /// Creates a copy of the current . /// @@ -66,21 +57,6 @@ namespace Spectre.Console return new Style(Foreground, Background, Decoration); } - /// - /// Converts the string representation of a style to its equivalent. - /// A return value indicates whether the operation succeeded. - /// - /// A string containing a style to parse. - /// - /// When this method returns, contains the equivalent of the text contained in , - /// if the conversion succeeded, or null if the conversion failed. - /// - /// true if s was converted successfully; otherwise, false. - public static bool TryParse(string text, out Style? result) - { - return StyleParser.TryParse(text, out result); - } - /// /// Combines this style with another one. /// @@ -108,6 +84,41 @@ namespace Spectre.Console return new Style(foreground, background, Decoration | other.Decoration); } + /// + /// Implicitly converts into a . + /// + /// The style string. + [SuppressMessage("Usage", "CA2225:Operator overloads have named alternates")] + public static explicit operator Style(string style) + { + return Parse(style); + } + + /// + /// Converts the string representation of a style to its equivalent. + /// + /// A string containing a style to parse. + /// A equivalent of the text contained in . + public static Style Parse(string text) + { + return StyleParser.Parse(text); + } + + /// + /// Converts the string representation of a style to its equivalent. + /// A return value indicates whether the operation succeeded. + /// + /// A string containing a style to parse. + /// + /// When this method returns, contains the equivalent of the text contained in , + /// if the conversion succeeded, or null if the conversion failed. + /// + /// true if s was converted successfully; otherwise, false. + public static bool TryParse(string text, out Style? result) + { + return StyleParser.TryParse(text, out result); + } + /// public override int GetHashCode() {