Provided the base class and the engine are in the same library you can use a shared interface that is private to your code only.
When implementing the interface on the base class ensure that you only do this explicitly and not implicitly. You will need to cast base class instances to the interface to use it but it should keep the methods private.
In your library
namespace ClassLibrary1
{
interface EngineInterface
{
void InterfaceMethod();
}
public class MyBaseClass : EngineInterface
{
private int myVar1;
public int Prop1
{
get { return myVar1; }
set { myVar1 = value; }
}
void EngineInterface.InterfaceMethod()
{
// do stuff
}
}
public static class EngineClass
{
public static void EngineMethod(MyBaseClass c1)
{
((EngineInterface)c1).InterfaceMethod();
}
}
}
When base class is used out side you library
namespace WindowsApplication1
{
class Class6 : ClassLibrary1.MyBaseClass
{
public void TestMethod()
{
ClassLibrary1.EngineClass.EngineMethod(this); // OK
((ClassLibrary1.EngineInterface)this).InterfaceMethod(); // Error: ClassLibrary1.EngineInterface is inaccessible dut to its protection level
}
}
} nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187