History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: RSRP-49160
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Alexander Zverev
Reporter: Drew Noakes
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ReSharper

Invalid fixes offered when attempting to use a type-local explicit interface member without casting 'this'

Created: 13 Sep 07 14:00   Updated: 17 Mar 08 12:53
Component/s: Quick Fixes
Fix Version/s: 4.0
Security Level: Everybody (All jira users)

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
File Attachments: None
Image Attachments:

1. ReSharper - Local usage of explicit interface method.png
(19 kb)

Build: 520


 Description  « Hide
See attached image.

Note also that in this case the Receive method is provided by the auto-complete function. If it's selected, ideally the correct cast would be inserted at that time.

If you choose any of the provided options, a visibility modifier is prepended to the target member which breaks the code.

Better options would be:

  • Use explicit interface method
  • Convert method to implicit implementation


 All   Comments   Work Log   Change History      Sort Order:
Drew Noakes - 13 Sep 07 14:07
Thinking about this a little more, I suppose the ideal solution is to invert the method that contains the code:

So, instead of...

        public void Add(T item)
        {
            (IReceiver<T>)this).Receive(item)
        }

...we have...

        public void Add(T item)
        {
            if (_disposed)
                throw new ObjectDisposedException("CrossThreadBuffer");

            lock (_buffer)
                _buffer.Receive(item);

            _event.Set();
        }

        void IReceiver<T>.Receive(T item)
        {
            Add(item);
        }

This avoids any casting. The runtime might even inline the methods or allocate them both as the same entry in the method table, if the type was sealed (pure speculation).