public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer) { var value = (string)reader.Value !; // ReSharper disable once HeapView.BoxingAllocation return(Base64Encoded.Decode(value)); }
public override object ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value) { if (value is string s) { // ReSharper disable once HeapView.BoxingAllocation return(Base64Encoded.Decode(s)); } return(base.ConvertFrom(context, culture, value) !); }
public Image( ImageType t, Base64Encoded b) { if (t is Valid) { Type = t; Data = b; } else { throw new Error($"Invalid imagetype {t}"); } }
public void BasicTest() { var b0 = default(Base64Encoded); b0.Count.Should().Be(0); b0.Data.Length.Should().Be(0); b0.Encode().Should().Be(""); var b0a = new Base64Encoded(Array.Empty <byte>()); b0a.Count.Should().Be(0); b0a.Data.Length.Should().Be(0); b0a.Encode().Should().Be(""); Equals(b0, b0a).Should().BeTrue(); var b1 = new Base64Encoded(new byte[] { 1 }); b1.Count.Should().Be(1); b1.Data.Length.Should().Be(1); Equals(b0, b1).Should().BeFalse(); }