Domanda

Can anyone guide me on creating a resharper structural search for the following signature:

namespace System
{
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext);
}

I'm trying to detect the use of this overload of the rx subscribe function as it has no onError handler specified, which causes exceptions in bad places. As such I want to match on any specialisation of T.

I've tried a few options and can't seem to get it matching the specific instance types of this generic type. My attempts only match on generic methods that explicitly with IObservable rather than a specialisation such as IObservable.

I have for instance tried:

Subscribe(System.IObservable<$type$>, Action<$type$>)

where $type$ is just a type placeholder of no specific type.

Thanks

È stato utile?

Soluzione 3

It is not currently possible, so jetbrains have opened a ticket.

http://youtrack.jetbrains.com/issue/RSRP-409075

Altri suggerimenti

I struggled to get any useful results from structured search for this. It's not great with generics.

I wondered if a regular expression search would prove useful. This found a lot of candidates for me:

\.Subscribe\([^,]*\)(?!,) 

Which has the logic of looking for strings that start “.Subscribe(“ and then don’t have a comma until a “)” is found without a comma after it. It’s a bit convoluted, but seems to handle the case where the OnNext expression is non-trivial reasonably well. Use at your own risk as it obviously won't be perfect.

Also, don't forget about the Subscribe extension method for just OnNext and OnCompleted handlers.

EDIT

As mentioned in the OP comments, R#'s "Find usages" also works and probably better than this - but I couldn't get an equivalent in structured search to work.

I think you want

Subscribe($id0$, $id1$)

where you constrain, from a dropdown menu, $id0$ and $id1$ to be arguments of a specific type

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top