ReSharper Live template that uses return type and parameter type

21 Views Asked by At

I have a lot of methods coming from implementing interfaces that are pretty much boiler plate code:

public ResponseType DoSomething(RequestType request)
{
    return HandleMessage<RequestType, ResponseType>(request);
}

Method signatures I get by using implement missing

The furthest I got is with this template:

return HandleMessage<$name$Request, $name$Response>(request);

Where $name$ is set to Containing type member name which uses method name to generate request response and I get something like

public DoAResponse DoA(DoARequest request)
{
    return HandleMessage<DoARequest , DoAResponse >(request);
}
public DoBResponse DoB(DoBRequest request)
{
    return HandleMessage<DoBRequest , DoBResponse >(request);
}

This works fine for most of my implementations but not for all. Is there any way I can make this more robust

**Edit more elaboration So basically this template just copy pastes method name and concatinates that string with words "Request"/"Response" So when I have implementations that look like this:

DoSomethingResponse DoSomethingElse(Message request);

Instead of

return HandleMessage<Message, DoSomethingResponse>(request);

I will get

return HandleMessage<DoSomethingElseRequest, DoSomethingElseResponse>(request);
0

There are 0 best solutions below