I would like to control in a class the signature of certain methods so that it throws a compilation error if a method does not have the signature I want.
I have thought do it creating a custom attribute, something like this:
public class CustomAttributeForMethodWithStringParameterFirstAttribute : Attribute
{
}
public class MyClass
{
[CustomAttributeForMethodWithStringParameterFirst]
public void Method1 (string p)
{
}
[CustomAttributeForMethodWithStringParameterFirst]
public void Method2 () // <--- I wish a compile error
{
}
}
But... Now I do not know how to continue. Is it possible do this via attributes?
Thanks in advance. If not, is there any way to do it?
EDIT Sorry, I have simplified my scenario to expone the concrete problem. I'm writting the interface for a WCF service and I wish implement this attributes in the interface. Certain methods must have one string parameters in first position for custom operations. I've developed a custom attribute to do something with this first parameter before methods calls of my service.
public interface MyInterface
{
[CustomAttributeForMethodWithStringParameterFirst]
void Method1 (string p);
[CustomAttributeForMethodWithStringParameterFirst]
void Method2 (); // <--- I wish a compile error
}