How to suppress suggestions for certain data types?

When I define properties in C# with type string[] or List<string>, ReSharper 6 suggest to replace the type by IEnumerable<string>.

This suggestion is OK in most cases. For particular types, like ObservableCollection<string>, it is not equivalent to use IEnumerable<string> instead, because frameworks like WPF depend on the type being ObservableCollection<...> (because ObservableCollection<...> implements INotifyCollectionChanged and INotifyPropertyChanged).

How can I tell ReSharper to suggest the replacement of a type base "IEnumerable<string>" only if the type is not ObservableCollection<...>?

Regards

- Frank

2 comments
Comment actions Permalink

Hello
     I'm afraid at the moment it's not possible to configure ReSharper in such way. Could you please provide a small sample solution where the change suggested by ReSharper breaks the application? Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

The problem is not that replacing the type by IEnumerable<...> would break the code; WPF is smart enough to determine the actual type at runtime.

The problem is that the code is less maintainable after the substition. For example, suppose you have the following code:

public class MyClass
{
    private ObservableCollection<string> _items = new ObservableCollection<string>();

    ...


    public ObservableCollection<string> Items
    {
        get
        {
             return _items;
        }
    }
}

With this code, it is clear to the maintainer of the code that (s)he never must change the type of _items to List<string> or to string[].

When the type of Items is changed to "IEnumerable<string>", the maintainer might think that (s)he can use any type for _items that implements "IEnumerable<string>". And that is wrong, of course.

Regards
- Frank

0

Please sign in to leave a comment.