How did Resharper do this?

Hello -- I'm a Resharper newbie, and it just did something (good) that surprised me, and I wanted to know what this option is called and whether / how it can be configured.
I have a program in which I assign a value to a property named Segments of type IEnumerable<Segment>. The value is created by a gigantic LINQ SelectMany, and details are unimportant. Right after the assignment, I started to type

foreach

and before I could blink, Resharper spit out

foreach (var segment in Segments)
{
}

which is, of course, exactly what I was going to say. I didn't expect anything to happen, let alone this spooky mindreading! How did it guess I was going to foreach over my newly created property and not over some other enumerable property in the class (there are a lot of other IEnumerables in the class)? How did it know that "segment" is a reasonable name for the var -- I didn't suggest it? Is it doing some kind of NLP along with the mind-reading?

again, this is cool and good, but I want to more about it so maybe I can *count* on it in the future :)

1 comment

This is a feature called "live templates".  There are many of them...
"foreach" is just one of them.

You can even code your own.

Look up "Live Templates" in the ReSharper Help to get you started.


"Brian Beckman"  wrote in message
news:12942653.345811310773745134.JavaMail.devnet@confluence.jetbrains.net...

Hello -- I'm a Resharper newbie, and it just did something (good) that
surprised me, and I wanted to know what this option is called and whether /
how it can be configured.
I have a program in which I assign a value to a property named Segments of
type IEnumerable. The value is created by a gigantic LINQ
SelectMany, and details are unimportant. Right after the assignment, I
started to type
foreach
and before I could blink, Resharper spit out
foreach (var segment in Segments)
{
}
which is, of course, exactly what I was going to say. I didn't expect
anything to happen, let alone this spooky mindreading! How did it guess I
was going to foreach over my newly created property and not over some other
enumerable property in the class (there are a lot of other IEnumerables in
the class)? How did it know that "segment" is a reasonable name for the
var -- I didn't suggest it? Is it doing some kind of NLP along with the
mind-reading?

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

0

Please sign in to leave a comment.