I am getting the same error in multiple places. I am converting some c# to vb .net when I try to define Public structures or classes that implements some Iinterface I get "class can only inherit from other classes". Many thanks to
A Simple - Yet Quite Powerful - Palette Quantizer in C#
by Smart K8. If there is any interest I'll post the VB version when it is working.
Here is an example of the problem:
The Interface:
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Runtime.InteropServices
Namespace ColorQuantizationVB.ColorCaches
Public Interface IColorCache
Sub Prepare()
Sub CachePalette(ByVal palette As IList(Of Color))
Sub GetColorPaletteIndex(ByVal color As Color, <Out> ByRef paletteIndex As Integer)
End Interface
End Namespace
Here is the Class:
Namespace ColorQuantizationVB.ColorCaches
Public MustInherit Class BaseColorCache
Inherits IColorCache
Private ReadOnly cache As ConcurrentDictionary(Of Integer, Integer)
Protected Property ColorModel As ColorModel
Public MustOverride ReadOnly Property IsColorModelSupported As Boolean
Protected Sub New()
cache = New ConcurrentDictionary(Of Integer, Integer)
End Sub
Public Sub ChangeColorModel(ByVal colorModel As ColorModel)
colorModel = colorModel
End Sub
Protected MustOverride Sub OnCachePalette(ByVal palette As IList(Of Color))
Protected MustOverride Sub OnGetColorPaletteIndex(ByVal color As Color, <Out> ByRef paletteIndex As Integer)
Public Overridable Sub Prepare()
cache.Clear()
End Sub
Public Sub CachePalette(ByVal palette As IList(Of Color))
OnCachePalette(palette)
End Sub
Public Sub GetColorPaletteIndex(ByVal color As Color, <Out> ByRef paletteIndex As Integer)
Dim key As Integer = color.R << 16 Or color.G << 8 Or color.B
paletteIndex = cache.AddOrUpdate(key, Function(colorKey)
Dim paletteIndexInside As Integer
OnGetColorPaletteIndex(color, paletteIndexInside)
Return paletteIndexInside
End Function, Function(colorKey, inputIndex) inputIndex)
End Sub
End Class
Here is the original C# code for the Iinterface
using System;
using System.Collections.Generic;
using System.Drawing;
namespace SimplePaletteQuantizer.ColorCaches
{
public interface IColorCache
{
void Prepare();
void CachePalette(IList<Color> palette);
void GetColorPaletteIndex(Color color, out Int32 paletteIndex);
}
}
and the base color class
using System;
using System.Collections.Concurrent;
using System.Drawing;
using System.Collections.Generic;
using SimplePaletteQuantizer.ColorCaches.Common;
namespace SimplePaletteQuantizer.ColorCaches
{
public abstract class BaseColorCache : IColorCache
{
#region | Fields |
private readonly ConcurrentDictionary<Int32, Int32> cache;
#endregion
#region | Properties |
protected ColorModel ColorModel { get; set; }
public abstract Boolean IsColorModelSupported { get; }
#endregion
#region | Constructors |
protected BaseColorCache()
{
cache = new ConcurrentDictionary<Int32, Int32>();
}
#endregion
#region | Methods |
public void ChangeColorModel(ColorModel colorModel)
{
ColorModel = colorModel;
}
#endregion
#region << Abstract methods |
protected abstract void OnCachePalette(IList<Color> palette);
protected abstract void OnGetColorPaletteIndex(Color color, out Int32 paletteIndex);
#endregion
#region << IColorCache >>
public virtual void Prepare()
{
cache.Clear();
}
public void CachePalette(IList<Color> palette)
{
OnCachePalette(palette);
}
public void GetColorPaletteIndex(Color color, out Int32 paletteIndex)
{
Int32 key = color.R << 16 | color.G << 8 | color.B;
paletteIndex = cache.AddOrUpdate(key,
colorKey =>
{
Int32 paletteIndexInside;
OnGetColorPaletteIndex(color, out paletteIndexInside);
return paletteIndexInside;
},
(colorKey, inputIndex) => inputIndex);
}
#endregion
}
}
What I have tried:
Ive tried playing around with MustInherit Inherit and Interface but I really have never quite understood how these interfaces work. I've tried reading up on Implementing IEnumerable and IEnumerator and my ears are bleeding the info out.
I'm old, bald too.