/// <summary> /// Gets the name of the color if it is defined in the <see cref="OxyColors" /> class. /// </summary> /// <param name="color">The color.</param> /// <returns>The color name or <c>null</c> if the color is not found.</returns> public static string GetColorName(this OxyColor color) { var t = typeof(OxyColors); #if NET40 var colors = t.GetProperties(BindingFlags.Static | BindingFlags.Public); var colorField = colors.FirstOrDefault(field => color.Equals(field.GetValue(null, null))); #else var colors = t.GetRuntimeFields().Where(fi => fi.IsPublic && fi.IsStatic); var colorField = colors.FirstOrDefault(field => color.Equals(field.GetValue(null))); #endif return(colorField != null ? colorField.Name : null); }
/// <summary> /// Gets the name of the color if it is defined in the <see cref="OxyColors" /> class. /// </summary> /// <param name="color">The color.</param> /// <returns>The color name or <c>null</c> if the color is not found.</returns> public static string GetColorName(this OxyColor color) { var t = typeof(OxyColors); var colors = t.GetRuntimeFields().Where(fi => fi.IsPublic && fi.IsStatic); var colorField = colors.FirstOrDefault(field => color.Equals(field.GetValue(null))); return(colorField != null ? colorField.Name : null); }
/// <summary> /// Converts a color to a svg color string. /// </summary> /// <param name="color">The color.</param> /// <returns>The color string.</returns> protected string ColorToString(OxyColor color) { if (color.Equals(OxyColors.Black)) { return("black"); } var formatString = "rgb({0:" + this.NumberFormat + "},{1:" + this.NumberFormat + "},{2:" + this.NumberFormat + "})"; return(string.Format(formatString, color.R, color.G, color.B)); }
/// <summary> /// Gets the name of the color if it is defined in the <see cref="OxyColors" /> class. /// </summary> /// <param name="color">The color.</param> /// <returns>The color name or <c>null</c> if the color is not found.</returns> public static string GetColorName(this OxyColor color) { var t = typeof(OxyColors); #if UNIVERSAL var colors = t.GetFields(); #else var colors = t.GetFields(BindingFlags.Public | BindingFlags.Static); #endif var colorField = colors.FirstOrDefault(field => color.Equals(field.GetValue(null))); return(colorField != null ? colorField.Name : null); }
/// <summary> /// Converts a color to a svg color string. /// </summary> /// <param name="color">The color.</param> /// <returns>The color string.</returns> protected string ColorToString(OxyColor color) { if (color.Equals(OxyColors.Black)) { return "black"; } var formatString = "rgb({0:" + this.NumberFormat + "},{1:" + this.NumberFormat + "},{2:" + this.NumberFormat + "})"; return string.Format(formatString, color.R, color.G, color.B); }
/// <summary> /// Gets the name of the color if it is defined in the <see cref="OxyColors" /> class. /// </summary> /// <param name="color">The color.</param> /// <returns>The color name or <c>null</c> if the color is not found.</returns> public static string GetColorName(this OxyColor color) { FieldInfo colorField = typeof(OxyColors).GetFields(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((FieldInfo field) => color.Equals(field.GetValue(null))); if (!(colorField != null)) { return(null); } return(colorField.Name); }