刚说不实用,先不讨论是不是实用,单纯的想把代码写的更优美,总结一下,主要内容在这
bool b = 1 == 1 ? ((Func<bool>)(() => true)).Invoke() : ((Func<bool>)(() => false)).Invoke();
能不能继续精简这样一句话?
其中 color仅仅为一个普通的JToken类型,需要精简的是,对于循环重复赋值上,能不能有更简单而且简洁的写法。。。
Byte red = 0, green = 0, blue = 0, alph = 255; JToken colorJToken = CurrentVersion < ColorVersion ? color.FirstOrDefault() : color; if (colorJToken != null) { foreach (var item in colorJToken) { var colorJProperty = item as JProperty; if (colorJProperty != null && colorJProperty.Value != null) { //以下求精简 (colorJProperty.Name == "a" ? ((Func<bool>)(() => (alph = (Byte)colorJProperty.Value).Equals(alph))).Invoke() : (colorJProperty.Name == "r" ? ((Func<bool>)(() => (red = (Byte)colorJProperty.Value).Equals(red))).Invoke() : (colorJProperty.Name == "g" ? ((Func<bool>)(() => (green = (Byte)colorJProperty.Value).Equals(green))).Invoke() : (colorJProperty.Name == "b" ? ((Func<bool>)(() => (blue = (Byte)colorJProperty.Value).Equals(blue))).Invoke() : ((Func<bool>)(() => false)).Invoke())))).ToString(); } } }