0

The interface is:

public interface CommonPluginInterface
{
    string GetPluginName();
    string GetPluginType();
    bool ElaborateReport();
}

now I want all derived classes to identify themselves through a string and an enum. For the string it's easy for it's hard coded:

public class PluginReport_Excel : MarshalByRefObject, CommonPluginInterface
{
    public string GetPluginName()
    {
        return "Foo";
    }
}

but additionally I want it to identify through an enum also. So I thought about putting in the interface but interface can't contain members.

So I thought about making

public class CommonPluginClass
{
    private enum ePluginType { UNKNOWN, EXCEL, EXCEL_SM, RTF}
    private ePluginType pluginType;
}

and making the derived class derive ALSO from that but this is not possible for it says:

Class 'PluginReport_Excel' cannot have multiple base classes: 'MarshalByRefObject' and 'CommonPluginClass'

and I need MarshalByRefObject. Thanks for any help.

Patrick
  • 3,073
  • 2
  • 22
  • 60

3 Answers3

1

You can use a property on the interface with the enum´s type:

public interface CommonPluginInterface
{
    string GetPluginName();
    bool ElaborateReport();
    ePluginType PluginType { get; }
}

Now all implementing classes also have to set the property accordingly. However you´ll ned the enumeration to be public.

public class PluginReport_Excel : MarshalByRefObject, CommonPluginInterface
{
    public string GetPluginName()
    {
        return "Foo";
    }
    public PluginType { get { return ePluginType.Excel; } }
}

Alternativly when you want to use the GetPluginType-method you may simply convert the enums value to string:

public class PluginReport_Excel : MarshalByRefObject, CommonPluginInterface
{
    public string GetPluginName()
    {
        return "Foo";
    }
    public string GetPluginType()
    {
        return this.PluginType.ToString();
    }
    public PluginType { get { return ePluginType.Excel; } }
}
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
1

How about creating a MarshalByRefCommonPluginClass?

public class MarshalByRefCommonPluginClass : MarshalByRefObject
{
    private enum ePluginType { UNKNOWN, EXCEL, EXCEL_SM, RTF}
    private ePluginType pluginType;
}

As an aside, naming conventions would normally mean interfaces have an 'I' prefix (ICommonPlugin) and types would use capital letters (EPluginType).

g t
  • 7,287
  • 7
  • 50
  • 85
1

Define an enum separately and define it as a return type for the GetPluginType method.

public enum ePluginType 
{ 
    UNKNOWN, 
    EXCEL, 
    EXCEL_SM, 
    RTF
} 

public interface CommonPluginInterface
{
    string GetPluginName();
    ePluginType GetPluginType();
    bool ElaborateReport();
}

public class PluginReport_Excel : MarshalByRefObject, CommonPluginInterface
{
    public ePluginType GetPluginType()
    {
        return ePluginType.EXCEL;
    }

    //implement other interface members
}
Andriy Tolstoy
  • 5,690
  • 2
  • 31
  • 30