private readonly ConcurrentDictionary<string, System.Drawing.Color> _colorSet;
public void BuildColorSet(IList<string> colorNames, string prefix, bool forceLastToGray)
{
var size = forceLastToGray ? colorNames.Count - 1 : colorNames.Count;
int nbHue = 6;
int nbCycle = (int)Math.Ceiling((double)size / nbHue);
var saturationMax = nbCycle <= 2 ? 1.0 : 1.0;
var saturationMin = 0.3;
var luminanceMax = nbCycle <= 2 ? 0.85 : 0.85;
var luminanceMin = 0.3;
var maxSaturationShift = 0.30;
var maxLuminanceShift = 0.15;
var interval = 1.0 / Math.Min(size, nbHue);
var saturationShift = (saturationMax - saturationMin) / (nbCycle - 1);
saturationShift = Math.Min(saturationShift, maxSaturationShift);
var luminanceShift = (luminanceMax - luminanceMin) / (nbCycle - 1);
luminanceShift = Math.Min(luminanceShift, maxLuminanceShift);
var hueShift = 0.0;
var saturation = saturationMax;
var luminance = luminanceMax;
for(var i = 0; i<size; i++)
{
if(i > 0 && (i % nbHue == 0)) // Next Cycle
{
saturation -= saturationShift;
luminance -= luminanceShift;
hueShift = hueShift == 0 ? interval/2 : 0;
}
var hue = interval*(i%nbHue) + hueShift;
System.Drawing.Color color = HSL2RGB(hue, saturation, luminance);
_colorSet.AddOrUpdate(prefix + colorNames[i], color, ???);
}
if(forceLastToGray)
{
_colorSet.TryAdd(prefix + colorNames[colorNames.Count - 1], System.Drawing.Color.LightGray);
}
_cssDirty = true;
}
如果颜色存在新值,我希望能够更新字典。如果字典中没有颜色,也可以添加到字典中。
我正在使用 AddOrUpdate 但无法获取 AddOrUpdate 方法的第三个参数(形成 lambda 表达式或委托方法)。
知道我的第三个参数会是什么样子吗?