我有一个可移植的类库,例如,公开了这个接口方法:
public interface IPortablePainter
{
void PaintTheSky(PortableColor color);
}
然后,我需要定义一些特定于平台的实现,(完全是发明的,仅举例):
Android实施:
public class AndroidPainter : IPortablePainter
{
public void PaintTheSky(PortableColor color)
{
AndroidFrameworkColor convertedColor = ToColor(color);
// DrawSky needs an AndroidFrameworkColor, not a PortableColor
AndroidFrameworkPainter.DrawSky(convertedColor);
}
}
public static AndroidFrameworkColor ToColor(PortableColor color)
{
return new AndroidFrameworkColor()
{
A = color.A,
R = color.R,
G = color.G,
B = color.B
};
}
iOS实施:
public class iOSPainter : IPortablePainter
{
public void PaintTheSky(PortableColor color)
{
iOSFrameworkColor convertedColor = ToColor(color);
// DrawSky needs an iOSFrameworkColor, not a PortableColor
iOSFrameworkPainter.DrawSky(convertedColor);
}
}
public static iOSFrameworkColor ToColor(PortableColor color)
{
return new iOSFrameworkColor()
{
AlphaChannel = color.A,
RedChannel = color.R,
GreenChannel = color.G,
BlueChannel = color.B
};
}
请注意,我不是AndroidFrameworkColor
和iOSFrameworkColor
,也不是AndroidFrameworkPainter
和iOSFrameworkPainter
,我无法触及该类的定义,将其视为构建在平台基础框架上。
问题是: