Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created November 15, 2020 19:10
Show Gist options
  • Save ucarion/1bb01bd2b78a3212c52b40ff7955c04a to your computer and use it in GitHub Desktop.
Save ucarion/1bb01bd2b78a3212c52b40ff7955c04a to your computer and use it in GitHub Desktop.
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