controlflow / resharper-postfix

ReSharper Postfix Templates plugin
MIT License
127 stars 12 forks source link

Fix flags enum completion #16

Closed controlflow closed 9 years ago

controlflow commented 10 years ago

When enum case takes >1 bit, should emit

(value & Enum.Case) == Enum.Case
hazzik commented 10 years ago

What is the snippet?

controlflow commented 10 years ago

To be clear, if you have enum like this:

[Flags]
enum E {
  A = 1 << 0,
  B = 1 << 1,
  C = 1 << 2,
  BC = B | C
}

When you complete BC fake member over value of type E, you will get:

void M(E e) {
  if ((e & E.BC) != 0) { }
}

This is wrong :) Right way was:

void M(E e) {
  if ((e & E.BC) == E.BC) { }
}
thinkingmedia commented 10 years ago

:+1:

controlflow commented 9 years ago

Fixed in upcoming 2.2