Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***********************************************************************
- // Author : ElektroStudios
- // Modified : 15-December-2016
- // ***********************************************************************
- #region Public Members Summary
- #region Constructors
- // New(Color)
- // New(Pen)
- // New(SolidBrush)
- #endregion
- #region Properties
- // Color As Color
- // ARGB As String
- // RGB As String
- // Hex As String
- // Web As String
- // Hsl As String
- // Win32 As String
- // Delphi As String
- // CSharp(CSharpColorFormat) As String
- // VisualBasic(VisualBasicColorFormat) As String
- // VisualStudio(VisualStudioColorFormat) As String
- #endregion
- #endregion
- #region Option Statements
- Option Strict On;
- Option Explicit On;
- Option Infer Off;
- #endregion
- #region Imports
- Imports System.ComponentModel;
- Imports System.Drawing;
- Imports System.Globalization;
- Imports System.Runtime.Serialization;
- Imports System.Security.Permissions;
- Imports System.Xml;
- Imports System.Xml.Serialization;
- #if ! NETCOREAPP
- Imports DevCase.ProjectMigration;
- #else
- Imports System.Runtime.Versioning;
- #endif
- #endregion
- #region Color-String
- // ReSharper disable once CheckNamespace
- Namespace DevCase.Core.Media.Graphics;
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Defines a <see cref="System.Drawing.Color"/> with an unique string-format representation in the specified string-syntax.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <example> This is a code example.
- /// <code language="VB.NET">
- /// Dim colorString As New ColorString(color.FromArgb(255, 91, 146, 198))
- ///
- /// Console.WriteLine(String.Format("ColorString Structure Size: {0}", Marshal.SizeOf(GetType(ColorString)).ToString()))
- /// Console.WriteLine(String.Format("Color.Tostring() : {0}", colorString.Color.ToString()))
- /// Console.WriteLine(String.Format("ColorString.Tostring() : {0}", colorString.ToString()))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("ARGB: {0}", colorString.Argb))
- /// Console.WriteLine(String.Format("RGB : {0}", colorString.Rgb))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("Hex : {0}", colorString.Hex))
- /// Console.WriteLine(String.Format("Web : {0}", colorString.Web))
- /// Console.WriteLine(String.Format("HSL : {0}", colorString.Hsl))
- /// Console.WriteLine(String.Format("Win32: {0}", colorString.Win32))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("Delphi: {0}", colorString.Delphi))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("C# (Int): {0}", colorString.CSharp(CSharpColorFormat.Int)))
- /// Console.WriteLine(String.Format("C# (Hex): {0}", colorString.CSharp(CSharpColorFormat.Hex)))
- /// Console.WriteLine(String.Format("C# (Web): {0}", colorString.CSharp(CSharpColorFormat.Html)))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("Vb.Net (Int): {0}", colorString.VisualBasic(VisualBasicColorFormat.Int)))
- /// Console.WriteLine(String.Format("Vb.Net (Hex): {0}", colorString.VisualBasic(VisualBasicColorFormat.Hex)))
- /// Console.WriteLine(String.Format("Vb.Net (Web): {0}", colorString.VisualBasic(VisualBasicColorFormat.Html)))
- /// Console.WriteLine()
- /// Console.WriteLine(String.Format("Visual Studio (Int): {0}", colorString.VisualStudio(VisualStudioColorFormat.Int)))
- /// Console.WriteLine(String.Format("Visual Studio (Hex): {0}", colorString.VisualStudio(VisualStudioColorFormat.Hex)))
- /// </code>
- /// </example>
- /// ----------------------------------------------------------------------------------------------------
- [Serializable]
- [XmlRoot(nameof(ColorString))]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification="Required to migrate this code to .NET Core")]
- Public NotInheritable Class ColorString : Implements ISerializable, IXmlSerializable;
- #region Properties
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the <see cref="System.Drawing.Color"/>.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The <see cref="System.Drawing.Color"/>.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- Public ReadOnly Property Color As Color;
- [DebuggerStepThrough]
- get
- {
- return this.colorB;
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// ( Backing field )
- /// The <see cref="System.Drawing.Color"/>.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- private Color colorB;
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the ARGB color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The ARGB color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Argb
- {
- [DebuggerStepThrough]
- get
- {
- return $"{Convert.ToString(this.colorB.A)}, {Convert.ToString(this.colorB.R)}, {Convert.ToString(this.colorB.G)}, {Convert.ToString(this.colorB.B)}";
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the RGB color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The RGB color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Rgb
- {
- [DebuggerStepThrough]
- get
- {
- return $"{Convert.ToString(this.colorB.R)}, {Convert.ToString(this.colorB.G)}, {Convert.ToString(this.colorB.B)}";
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the HSL color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The HSL color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Hsl
- {
- [DebuggerStepThrough]
- get
- {
- return $@"{this.colorB.GetHue():n0}, {_
- (this.colorB.GetSaturation() * 100).ToString("n1", CultureInfo.GetCultureInfo("en-US@").NumberFormat) _
- }%, {_
- (this.colorB.GetBrightness() * 100).ToString("n1", CultureInfo.GetCultureInfo("en-US@").NumberFormat) _
- }%";
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the Hexadecimal color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The Hexadecimal color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Hex
- {
- [DebuggerStepThrough]
- get
- {
- string a = Convert.ToString(this.colorB.A, 16).ToUpper();
- string r = Convert.ToString(this.colorB.R, 16).ToUpper();
- string g = Convert.ToString(this.colorB.G, 16).ToUpper();
- string b = Convert.ToString(this.colorB.B, 16).ToUpper();
- return $"{a}{r}{g}{b}";
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the Web color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The Web color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Web
- {
- [DebuggerStepThrough]
- get
- {
- return ColorTranslator.ToHtml(this.Color);
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the Win32 color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The Win32 color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Win32
- {
- [DebuggerStepThrough]
- get
- {
- // Return CStr(ColorExtensions.ToWin32(Me.colorB))
- return ColorTranslator.ToWin32(this.colorB).ToString();
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the Delphi color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The Delphi color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- public string Delphi
- {
- [DebuggerStepThrough]
- get
- {
- string a = Convert.ToString(this.colorB.A, 16).ToUpper();
- string r = Convert.ToString(this.colorB.R, 16).ToUpper();
- string g = Convert.ToString(this.colorB.G, 16).ToUpper();
- string b = Convert.ToString(this.colorB.B, 16).ToUpper();
- return $"$00{a}{r}{g}{b}";
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the C# color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The C# color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# NOTE: C# does not support parameterized properties - the following property has been rewritten as a function:
- // ORIGINAL LINE: Public ReadOnly Property CSharp(format As CSharpColorFormat) As String
- public string get_CSharp(CSharpColorFormat format)
- {
- <DebuggerStepThrough> Get
- return this.GetCSharpString(format)
- End Get
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the VisualBasic color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The VisualBasic color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# NOTE: C# does not support parameterized properties - the following property has been rewritten as a function:
- // ORIGINAL LINE: Public ReadOnly Property VisualBasic(format As VisualBasicColorFormat) As String
- public string get_VisualBasic(VisualBasicColorFormat format)
- {
- <DebuggerStepThrough> Get
- return this.GetVisualBasicString(format)
- End Get
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the VisualStudio color representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <value>
- /// The VisualStudio color representation.
- /// </value>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# NOTE: C# does not support parameterized properties - the following property has been rewritten as a function:
- // ORIGINAL LINE: Public ReadOnly Property VisualStudio(format As VisualStudioColorFormat) As String
- public string get_VisualStudio(VisualStudioColorFormat format)
- {
- <DebuggerStepThrough> Get
- return this.GetVisualStudioString(format)
- End Get
- }
- #endregion
- #region Constructors
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Prevents a default instance of the <see cref="ColorString"/> class from being created.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# TASK: This method is a constructor, but no class name was found:
- private <class name>()
- {
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Initializes a new instance of the <see cref="ColorString"/> class.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="color">
- /// The source <see cref="System.Drawing.Color"/>.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# TASK: This method is a constructor, but no class name was found:
- [DebuggerStepThrough]
- public <class name>(Color color)
- {
- this.colorB = color;
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Initializes a new instance of the <see cref="ColorString"/> class.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="pen">
- /// The source <see cref="Pen"/>.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# TASK: This method is a constructor, but no class name was found:
- [DebuggerStepThrough]
- [SupportedOSPlatform("windows")]
- public <class name>(Pen pen) : this(pen.Color)
- {
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Initializes a new instance of the <see cref="ColorString"/> class.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="brush">
- /// The source <see cref="SolidBrush"/>.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# TASK: This method is a constructor, but no class name was found:
- [DebuggerStepThrough]
- [SupportedOSPlatform("windows")]
- public <class name>(SolidBrush brush) : this(brush.Color)
- {
- }
- #endregion
- #region Operator Conversions
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Performs an implicit conversion from <see cref="ColorString"/> to <see cref="System.Drawing.Color"/>.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="colorString">
- /// The <see cref="ColorString"/>.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The resulting <see cref="System.Drawing.Color"/> of the conversion.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public static implicit operator Color(ColorString colorString)
- {
- return System.Drawing.Color.FromArgb(colorString.Color.R, colorString.Color.G, colorString.Color.B);
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Performs an implicit conversion from <see cref="System.Drawing.Color"/> to <see cref="ColorString"/>.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="color">
- /// The <see cref="System.Drawing.Color"/>.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The resulting <see cref="ColorString"/> of the conversion.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public static explicit operator ColorString(Color color)
- {
- return new ColorString(color);
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Implements the operator =.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="colorString1">
- /// The first <see cref="ColorString"/> to evaluate.
- /// </param>
- ///
- /// <param name="colorString2">
- /// The second <see cref="ColorString"/> to evaluate.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The result of the operator.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public static bool operator == (ColorString colorString1, ColorString colorString2)
- {
- return colorString1.Equals(colorString2);
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Implements the operator <>.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="colorString1">
- /// The first <see cref="ColorString"/> to evaluate.
- /// </param>
- ///
- /// <param name="colorString2">
- /// The second <see cref="ColorString"/> to evaluate.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The result of the operator.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public static bool operator != (ColorString colorString1, ColorString colorString2)
- {
- return !colorString1.Equals(colorString2);
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Determines whether the specified <see cref="Object"/> is equal to this instance.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="obj">
- /// Another object to compare to.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// <see langword="True"/> if the specified <see cref="Object"/> is equal to this instance; otherwise, <see langword="False"/>.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public override bool Equals(object obj)
- {
- if (obj is ColorString)
- {
- return this.Equals((ColorString)obj);
- }
- else if (obj is Color)
- {
- return this.Equals(new ColorString((Color)obj));
- }
- else
- {
- return false;
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Determines whether the specified <see cref="ColorString"/> is equal to this instance.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="colorString">
- /// Another <see cref="ColorString"/> to compare to.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// <see langword="True"/> if the specified <see cref="ColorString"/> is equal to this instance; otherwise, <see langword="False"/>.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- new public bool Equals(ColorString colorString)
- {
- return colorString.Color.ToArgb == this.colorB.ToArgb;
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Returns a hash code for this instance.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- public override int GetHashCode()
- {
- return this.colorB.GetHashCode();
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Returns a <see cref="String"/> that represents this instance.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// A <see cref="String"/> that represents this instance.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- [EditorBrowsable(EditorBrowsableState.Always)]
- [DebuggerNonUserCode]
- public override string ToString()
- {
- return string.Format(CultureInfo.CurrentCulture, "{{A={0}, R={1}, G={2}, B={3}}}", this.colorB.A, this.colorB.R, this.colorB.G, this.colorB.B);
- }
- #endregion
- #region ISerializable implementation // For Binary serialization.
- #pragma warning disable SYSLIB0003, SYSLIB0050 // Type or member is obsolete
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="info">
- /// The <see cref="SerializationInfo"/> to populate with data.
- /// </param>
- ///
- /// <param name="context">
- /// The destination (see <see cref="StreamingContext"/>) for this serialization.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <exception cref="ArgumentNullException">
- /// info
- /// </exception>
- /// ----------------------------------------------------------------------------------------------------
- [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
- [DebuggerStepThrough]
- [EditorBrowsable(EditorBrowsableState.Never)]
- private void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- #pragma warning restore SYSLIB0003, SYSLIB0050 // Type or member is obsolete
- #if ! NETCOREAPP
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- #else
- ArgumentNullException.ThrowIfNull(info, nameof(info));
- #endif
- info.AddValue("ARGB", this.colorB.ToArgb, typeof(int));
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Initializes a new instance of the <see cref="ColorString"/> class.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <remarks>
- /// This constructor is used to deserialize values.
- /// </remarks>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="info">
- /// The <see cref="SerializationInfo"/> to populate with data.
- /// </param>
- ///
- /// <param name="context">
- /// The destination (see <see cref="StreamingContext"/>) for this deserialization.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <exception cref="ArgumentNullException">
- /// info
- /// </exception>
- /// ----------------------------------------------------------------------------------------------------
- // INSTANT C# TASK: This method is a constructor, but no class name was found:
- [DebuggerStepThrough]
- [EditorBrowsable(EditorBrowsableState.Never)]
- private <class name>(SerializationInfo info, StreamingContext context)
- {
- #if ! NETCOREAPP
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- #else
- ArgumentNullException.ThrowIfNull(info, nameof(info));
- #endif
- this.colorB = System.Drawing.Color.FromArgb(info.GetInt32("ARGB"));
- }
- #endregion
- #region IXMLSerializable implementation // For Xml serialization.
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// This method is reserved and should not be used.
- /// When implementing the <see cref="IXmlSerializable"/> interface, you should return <see langword="Nothing"/> from this method,
- /// and instead, if specifying a custom schema is required, apply the <see cref="XmlSchemaProviderAttribute"/> to the class.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// An <see cref="Schema.XmlSchema"/> that describes the Xml representation of the object
- /// that is produced by the <c>IXmlSerializable.WriteXml(Xml.XmlWriter)</c> method
- /// and consumed by the <c>IXmlSerializable.ReadXml(Xml.XmlReader)</c> method.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerNonUserCode]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public System.Xml.Schema.XmlSchema GetSchema()
- {
- return null;
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Converts an object into its Xml representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="writer">
- /// The <see cref="XmlWriter"/> stream to which the object is serialized.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerStepThrough]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void WriteXml(XmlWriter writer)
- {
- writer.WriteElementString("ARGB", this.colorB.ToArgb.ToString());
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Generates an object from its Xml representation.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="reader">
- /// The <see cref="XmlReader"/> stream from which the object is deserialized.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerStepThrough]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public void ReadXml(XmlReader reader)
- {
- reader.ReadStartElement("Color");
- this.colorB = System.Drawing.Color.FromArgb(int.Parse(reader.ReadElementContentAsString()));
- }
- #endregion
- #region Private Methods
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the C# representation of a <see cref="System.Drawing.Color"/>, in the specified format.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The resulting string representation.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- /// <exception cref="InvalidEnumArgumentException">
- /// format
- /// </exception>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerStepThrough]
- private string GetCSharpString(CSharpColorFormat format)
- {
- switch (format)
- {
- case CSharpColorFormat.Int:
- string byteString = $@"{Convert.ToString(this.colorB.A)}, {Convert.ToString(this.colorB.R)}, {_
- Convert.ToString(this.colorB.G)}, {Convert.ToString(this.colorB.B)}";
- return $"Color.FromArgb({byteString});";
- case CSharpColorFormat.Hex:
- string a = Convert.ToString(this.colorB.A, 16).ToUpper();
- string r = Convert.ToString(this.colorB.R, 16).ToUpper();
- string g = Convert.ToString(this.colorB.G, 16).ToUpper();
- string b = Convert.ToString(this.colorB.B, 16).ToUpper();
- return $"Color.FromArgb(0x{a}, 0x{r}, 0x{g}, 0x{b});";
- case CSharpColorFormat.Html:
- string htmlString = ColorTranslator.ToHtml(this.Color);
- return string.Format("ColorTranslator.FromHtml(\"{0}\");", htmlString, TangibleStringInterpolationMarker);
- default:
- throw new InvalidEnumArgumentException(nameof(format), format, typeof(CSharpColorFormat));
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the VisualBasic representation of a <see cref="System.Drawing.Color"/>, in the specified format.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The resulting string representation.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- /// <exception cref="InvalidEnumArgumentException">
- /// format
- /// </exception>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerStepThrough]
- private string GetVisualBasicString(VisualBasicColorFormat format)
- {
- switch (format)
- {
- case VisualBasicColorFormat.Int:
- string byteString = $@"{Convert.ToString(this.colorB.A)}, {Convert.ToString(this.colorB.R)}, {_
- Convert.ToString(this.colorB.G)}, {Convert.ToString(this.colorB.B)}";
- return $"Color.FromArgb({byteString})";
- case VisualBasicColorFormat.Hex:
- string a = Convert.ToString(this.colorB.A, 16).ToUpper();
- string r = Convert.ToString(this.colorB.R, 16).ToUpper();
- string g = Convert.ToString(this.colorB.G, 16).ToUpper();
- string b = Convert.ToString(this.colorB.B, 16).ToUpper();
- return $"Color.FromArgb(&H{a}, &H{r}, &H{g}, &H{b})";
- case VisualBasicColorFormat.Html:
- string htmlString = ColorTranslator.ToHtml(this.Color);
- return string.Format("ColorTranslator.FromHtml(\"{0}\")", htmlString, TangibleStringInterpolationMarker);
- default:
- throw new InvalidEnumArgumentException(nameof(format), format, typeof(VisualBasicColorFormat));
- }
- }
- /// ----------------------------------------------------------------------------------------------------
- /// <summary>
- /// Gets the Visual Studio representation of a <see cref="System.Drawing.Color"/>, in the specified format.
- /// </summary>
- /// ----------------------------------------------------------------------------------------------------
- /// <param name="format">
- /// The color format.
- /// </param>
- /// ----------------------------------------------------------------------------------------------------
- /// <returns>
- /// The resulting string representation.
- /// </returns>
- /// ----------------------------------------------------------------------------------------------------
- /// <exception cref="InvalidEnumArgumentException">
- /// format
- /// </exception>
- /// ----------------------------------------------------------------------------------------------------
- [DebuggerStepThrough]
- private string GetVisualStudioString(VisualStudioColorFormat format)
- {
- switch (format)
- {
- case VisualStudioColorFormat.Int:
- return $@"{Convert.ToString(this.colorB.A)}; {Convert.ToString(this.colorB.R)}; {_
- Convert.ToString(this.colorB.G)}; {Convert.ToString(this.colorB.B)}";
- case VisualStudioColorFormat.Hex:
- string a = Convert.ToString(this.colorB.A, 16).ToUpper();
- string r = Convert.ToString(this.colorB.R, 16).ToUpper();
- string g = Convert.ToString(this.colorB.G, 16).ToUpper();
- string b = Convert.ToString(this.colorB.B, 16).ToUpper();
- return $"0x{a}{r}{g}{b}";
- default:
- throw new InvalidEnumArgumentException(nameof(format), format, typeof(VisualStudioColorFormat));
- }
- }
- #endregion
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement