Created
January 4, 2016 14:20
-
-
Save JimBobSquarePants/ef9e482470dde4967ba1 to your computer and use it in GitHub Desktop.
Generic operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Color<T> operator +(Color<T> left, Color<T> right) | |
| { | |
| if (typeof(T) == typeof(byte)) | |
| { | |
| return (Color<T>)(object)new Color<byte>( | |
| (byte)((byte)(object)left.R + (byte)(object)right.R), | |
| (byte)((byte)(object)left.G + (byte)(object)right.G), | |
| (byte)((byte)(object)left.B + (byte)(object)right.B), | |
| (byte)((byte)(object)left.A + (byte)(object)right.A)); | |
| } | |
| // etc | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Double cast is required due to C# widening when adding to bytes.