entity framework - Best practices for returning a Color.FromArgb when given an int that may be null C# -


i curious best practices solution given current situation. have database storing colors in argb integer form, allow nullable since color may not need specified. using entity framework, have generated class colorargb property accessing column returns , int, expected. i've manually added property, color, returns system.drawing.color object. color property pretty go between can interact generated class in more natural fashion. setting simple as:

colorargb = value.toargb(); 

however, getting little more interesting. here's have far:

return colorargb == null ? color.empty : color.fromargb(colorargb ?? 0); 

as can see, want maintain idea color not necessary class, return color.empty when underlying argb value null, right hand side of null coalescing operator never reached. have guaranteed value not null, don't know how explicitly tell compiler in best practices form. not serious issue, learn. such, appreciated.

edit: colorargb of type system.nullable<int>

you don't have use null coalescing operator if know value not null. instead use colorargb.value:

return colorargb == null ? color.empty : color.fromargb(colorargb.value); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -