Skip to content

Convert color name to HEX #2250

Answered by ashahabov
ashahabov asked this question in Q&A
Sep 12, 2022 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

Found solution via reflection:

var inputClrName = "blue";

var fieldInfo = typeof(SKColors).GetFields(BindingFlags.Static | BindingFlags.Public)
                                             .First(fieldInfo => fieldInfo.Name.ToLower() == inputClrName);
var color = (SKColor)fieldInfo.GetValue(null);

var outputHexString = color.ToString();

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@ashahabov
Comment options

@mattleibow
Comment options

@mattleibow
Comment options

@ashahabov
Comment options

@mattleibow
Comment options

Comment options

You must be logged in to vote
1 reply
@mattleibow
Comment options

Answer selected by mattleibow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants