How to make a Custom Pattern that is slightly recursive?

We have extension methods To<T> and As<T> that do a fluent style version of (T)v and (v as T). I'd like to make a custom pattern to find redundant uses of these when the underlying 'v' is already of type T.

So I would like to do something like this:

   pattern = $expr$.To<$type$>()
   replace = $expr$

Where $expr$ is an expression of type $type$. This obviously doesn't work.

So in effect I'm looking for something similar to R#'s built-in ability to detect unnecessary use of Cast<T>() on an enumerable. Is this something I can do with a Custom Pattern?

1 comment

Hello Scott,

I guess this is not possible via custom SSR pattern. However, it should be
possible to do this as a small ReSharper plug-in. Thank you!

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

We have extension methods To<T> and As<T> that do a fluent style
version of (T)v and (v as T). I'd like to make a custom pattern to
find redundant uses of these when the underlying 'v' is already of
type T.

So I would like to do something like this:

pattern = $expr$.To<$type$>()
replace = $expr$
Where $expr$ is an expression of type $type$. This obviously doesn't
work.

So in effect I'm looking for something similar to R#'s built-in
ability to detect unnecessary use of Cast<T>() on an enumerable. Is
this something I can do with a Custom Pattern?

---
Original message URL:
http://devnet.jetbrains.net/message/5308507#5308507



0

Please sign in to leave a comment.