publicstaticboolSetColor(ref Color currentValue, Color newValue) { if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a) returnfalse;
currentValue = newValue; returntrue; }
SetStruct:比较两个结构体的值,如果为不一样才进行更新
1 2 3 4 5 6 7 8
publicstaticboolSetStruct<T>(ref T currentValue, T newValue) where T : struct { if (EqualityComparer<T>.Default.Equals(currentValue, newValue)) returnfalse;
currentValue = newValue; returntrue; }
SetClass:比较两个类的值,如果不一样且都不为空才进行更新
1 2 3 4 5 6 7 8
publicstaticboolSetClass<T>(ref T currentValue, T newValue) where T : class { if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) returnfalse;