Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to method groups without class instance #13343

Closed
miniBill opened this issue Aug 24, 2016 · 2 comments
Closed

Access to method groups without class instance #13343

miniBill opened this issue Aug 24, 2016 · 2 comments

Comments

@miniBill
Copy link

Would it make sense to allow explicit access to method groups, without a class instance?
Examples:

class Foo
{
    public void Bar() { }

    public int Baz { get; set; }

    public event EventHandler Poke;
}

class Program {
    public static void Main()
    {
        Action<Foo> bar = Foo.Bar;
        Func<Foo, int> bazGetter = Foo.Baz.get;
        Action<Foo, EventHandler> pokeAdder = Foo.Poke.add;

        Foo f = new Foo();
        bar(f); // Equivalent to f.Bar();
        int b = bazGetter(f); // Equivalent to int b = f.Baz;
        pokeAdder(f, (sender, e) => { }); // Equivalent to f.Poke += (sender, e) => { };
    }
}

I know that all three forms can be written right now, like this:

        Action<Foo> bar = f => f.Bar();
        Func<Foo, int> bazGetter = f => f.Baz;
        Action<Foo, EventHandler> pokeAdder = (f, h) => f.Poke += h;

but the syntax above would be nicer (and probably better for the type inference, because Foo.Bar has an obvious type, whereas f => f.Bar() needs a type annotation).

@HaloFour
Copy link

Similar to #5444.

@miniBill
Copy link
Author

Closing as dupe of #5444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants