I am currently writing a library that encodes and decodes images in qoi format. This image format uses rgb and rgba pixel formats.
I made the IPixel
interface and two implementations RgbPixel
and RgbaPixel
. IPixel
is not intended to be used as an extension point (because there are only rgb and rgba), I made this interface to use generic classes so as not to write the same thing twice.
RgbPixel
and RgbaPixel
are structs with the [StructLayout]
attribute. Some of my generic classes use unsafe code to unsafely cast these structs and other unmanaged types to each other to improve performance, so if user/another implementation of IPixel
gets to them, it will most likely cause an exception.
To avoid all these problems, I would like to allow only internal implementation of the IPixel
interface. But I don't know how to do it in C#.
If IPixel
were an abstract class, I could prevent implementation from other assemblies by having only internal constructors. But I can only use interfaces because I need RgbPixel
and RgbaPixel
to be structs.
.netstandart 2.0, c# 10.0