0

There is general service interface that been implemented by multi technologies.

For example, I have 2 interfaces:

  1. IGenralService
  2. IWcfService that inherit from IGenralService.

The base interface:

    public interface IGenralService
    {
         bool Login(string username, string password);
    }

And the wcf service:

public interface IWcfService : IGenralService
{
    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(Exception))]
    void DoSomething();
}

The IWcfService is specific for Wcf and need "OperationContract" attribute for wcf methods. The "Login" method does not including the attribute "OperationContract".

Is there any way to add attribute to the inherent method?

Moshe Levi
  • 21
  • 4
  • 1
    You want the `Login`-method for `IWcfService` to be decorated with an attribute, but not for `IGeneralService`? This is basically non-sense as any class implementing any of your interfaces doesn´t inherit its attributes, you´d have to re-declare them. So you can omit them in the interface anyway. – MakePeaceGreatAgain Jan 19 '17 at 15:22

1 Answers1

2

I suppose this is not possible, as attributes are not inherited to classes implementing an interface. So basically adding attributes to interface-members is quite useless, you have to do this on the classes themselves:

public class WcfService : IWcfService 
{
    [OperationContract(IsOneWay = false)]
    [FaultContract(typeof(Exception))]
    void DoSomething() { ... }
}

Alternativly you can also make your interface an abstract class whereby you can inherit attributes. Have a look at this post for how to do this.

Community
  • 1
  • 1
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111