Пока это то, что я придумал. У меня есть интерфейс с именем IImageCreator, и все кодеки создаются в
Код: Выделить всё
static readonly List _creators
Код: Выделить всё
abstract class ImageCreator : IImageCreator
Код: Выделить всё
sealed class SKBitmapImageCreator : ImageCreator {...}
sealed class WindowsBitmapImageCreator : ImageCreator {...}
У меня есть статический метод для кодирования изображения:
Код: Выделить всё
static BlkImgDataSrc ToPortableImageSource(object imageObject)
{
_creators.Single(c => c.GetType().GetTypeInfo().IsAssignableFrom(imageObject.GetType().GetTypeInfo()));
Обратите внимание, что imageObject будет иметь обрабатываемый тип, например SKBitmap.
У меня создалось впечатление, что это позволит определить правильный экземпляр для обработки imageObject на основе документация:
Код: Выделить всё
Returns true if any of the following conditions is true:
(...)
c is a generic type parameter, and the current instance represents one of the constraints of c.
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-c-sharp
Мобильная версия