Created
November 15, 2020 19:10
-
-
Save ucarion/1bb01bd2b78a3212c52b40ff7955c04a to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Newtonsoft.Json; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
RgbaColor color = JsonConvert.DeserializeObject<RgbaColor>("{\"Hex\": 0, \"Red\": 128}"); | |
Console.WriteLine(color.Hex); | |
Console.WriteLine(color.Red); | |
color = JsonConvert.DeserializeObject<RgbaColor>("{\"Red\": 128, \"Hex\": 0}"); | |
Console.WriteLine(color.Hex); | |
Console.WriteLine(color.Red); | |
} | |
private class RgbaColor | |
{ | |
public int Hex { get; set; } | |
public byte Red | |
{ | |
get => (byte) ((Hex & 0xff0000) >> 16); | |
set | |
{ | |
Hex = (Hex & 0x00ffff) | (((int) value) << 16); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment