Search with Pattern with generic types

Hi,

We've started using Reactive Extentions (Rx) quite heavily in our current project. We were hoping to use Resharper's Search with Pattern/Pattern Catalogue feature to allow us to give devs some hints and guidance.

I've defined the following pattern:

<CustomPatterns>
  <Pattern Severity="SUGGESTION">
    <ReplacePattern IsNull="True" />
    <SearchPattern>$obs$.Subscribe($action$)</SearchPattern>
    <Params />
    <Placeholders>
      <ExpressionPlaceholder Name="obs" ExpressionType="System.IObservable&lt;string&gt;" ExactType="False" />
      <ExpressionPlaceholder Name="action" ExpressionType="System.Action&lt;string&gt;" ExactType="False" />
    </Placeholders>
  </Pattern>
</CustomPatterns>


This basically searches for all uses of the IObservable<T>.Subscribe(Action<T>) extension method. In the above, I've had to provide a concrete type (string) to get it to find anything.

Is there anyway I can leave the generic type undefined (T)? I tried specifying a type of 'object', but it seems that co/contravariance has not yet made it into this part of Resharper.

Can anyone provide any hints?

Regards
Matt

4 comments

Hello Matt,

Generic type constraints are not supported by SSR at the moment. You're welcome
to vote for the following feature request: http://youtrack.jetbrains.net/issue/RSRP-153377.
Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hi,

We've started using Reactive Extentions (Rx) quite heavily in our
current project. We were hoping to use Resharper's Search with
Pattern/Pattern Catalogue feature to allow us to give devs some hints
and guidance.

I've defined the following pattern:

 
> 
> 
> $obs$.Subscribe($action$)
> 
> 
>  ExpressionType="System.IObservable<string>" ExactType="False" />
>  ExpressionType="System.Action<string>" ExactType="False" />
> 
> 
> ]]>

This basically searches for all uses of the
IObservable<T>.Subscribe(Action<T>) extension method. In the above,
I've had to provide a concrete type (string) to get it to find
anything.

Is there anyway I can leave the generic type undefined (T)? I tried
specifying a type of 'object', but it seems that co/contravariance has
not yet made it into this part of Resharper.

Can anyone provide any hints?

Regards
Matt
---
Original message URL:
http://devnet.jetbrains.net/message/5292359#5292359



0

Hi Andrey

Thanks for your response.

Your response to another user's question at http://devnet.jetbrains.net/message/5281864#5281864 seems to imply that you got it working?

I wonder if you could just explain what you meant in that post?

Thanks very much.

Regards
Matt

0

Hello Matt,

As I mentioned in that post, I got it working by replacing T with a concrete
type (string for instance), which is exactly the same scenario as yours (works
with a concrete type, but doesn't work for general T). Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hi Andrey

Thanks for your response.

Your response to another user's question at
http://devnet.jetbrains.net/message/5281864#5281864 seems to imply
that you got it working?

I wonder if you could just explain what you meant in that post?

Thanks very much.

Regards
Matt
---
Original message URL:
http://devnet.jetbrains.net/message/5292417#5292417



0

Ah, I see! Thank you very much.

I've voted on the issue, and will be rallying others to the cause.. this is an incredibly powerful feature for improving code quality, that is pretty much useless in all but the most basic of situations currently.

Thanks for your help.

Regards
Matt

0

Please sign in to leave a comment.