Suggestion (perhaps): Resolve event accessors differently #23

Open
opened 2012-03-11 18:16:39 -05:00 by erik-kallen · 3 comments
erik-kallen commented 2012-03-11 18:16:39 -05:00 (Migrated from github.com)

Currently, the expression MyEvent += MyHandler is resolved to a compound AddAssign. This works, but it is a little unintuitive since the semantics is not an addition at all, but it's just syntactic sugar for a method invocation. I guess this also means that find references won't work for event add accessor

Failing test:

        [Test]
        public void FindAddEventAccessor()
        {
            Init(@"using System;
class Test {
 public event EventHandler MyEvent { add {} remove {} }
 static void T() {
  MyEvent += null;
 }
}");
            var test = compilation.MainAssembly.TopLevelTypeDefinitions.Single(t => t.Name == "Test");
            var addAccessor = test.Events.Single(m => m.Name == "MyEvent").AddAccessor;
            var actual = FindReferences(addAccessor).ToList();
            Assert.IsTrue(actual.Any(r => r.StartLocation.Line == 5));
        }
Currently, the expression `MyEvent += MyHandler` is resolved to a compound AddAssign. This works, but it is a little unintuitive since the semantics is not an addition at all, but it's just syntactic sugar for a method invocation. I guess this also means that find references won't work for event add accessor Failing test: ``` [Test] public void FindAddEventAccessor() { Init(@"using System; class Test { public event EventHandler MyEvent { add {} remove {} } static void T() { MyEvent += null; } }"); var test = compilation.MainAssembly.TopLevelTypeDefinitions.Single(t => t.Name == "Test"); var addAccessor = test.Events.Single(m => m.Name == "MyEvent").AddAccessor; var actual = FindReferences(addAccessor).ToList(); Assert.IsTrue(actual.Any(r => r.StartLocation.Line == 5)); } ```
dgrunwald commented 2012-03-15 11:32:50 -05:00 (Migrated from github.com)

I would like to keep this consistent with properties, and there I prefer a compound AddAssign over nested calls set_X(get_X() + ...).

I would like to keep this consistent with properties, and there I prefer a compound AddAssign over nested calls `set_X(get_X() + ...)`.
erik-kallen commented 2012-03-15 12:47:54 -05:00 (Migrated from github.com)

Will you use the compound add assign in VB as well (where the syntax is AddHandler Event, Handler)

Will you use the compound add assign in VB as well (where the syntax is `AddHandler Event, Handler`)
dgrunwald commented 2012-03-15 16:07:33 -05:00 (Migrated from github.com)

We don't have any plans for Visual Basic support right now.

We certainly don't have the resources to write a full VB resolver that produces the same detail level as our C# resolver, so we'll probably just write a small resolver that handles the most important constructs. Or maybe we will use Roslyn and not use NR ResolveResults at all for VB.

We don't have any plans for Visual Basic support right now. We certainly don't have the resources to write a full VB resolver that produces the same detail level as our C# resolver, so we'll probably just write a small resolver that handles the most important constructs. Or maybe we will use Roslyn and not use NR ResolveResults at all for VB.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/NRefactory#23
No description provided.