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

Revisit ObjectExtensions.This() internal extension method #448

Open
Eilon opened this issue May 27, 2022 · 4 comments
Open

Revisit ObjectExtensions.This() internal extension method #448

Eilon opened this issue May 27, 2022 · 4 comments
Labels
area-mobileblazorbindings Experimental Mobile Bindings for Blazor

Comments

@Eilon
Copy link
Member

Eilon commented May 27, 2022

In #345 a new internal extension method was added to make creating more efficient delegates easier.

We should consider an approach that avoids extension methods on object, such as using a regular static method.

@Eilon Eilon added the area-mobileblazorbindings Experimental Mobile Bindings for Blazor label May 27, 2022
@Eilon
Copy link
Member Author

Eilon commented May 28, 2022

Interesting, that is definitely something to consider. I wonder if there's some clever syntax to avoid reflection and have the compiler provide the delegate with the right identity? It's just so unusual for extension methods to provide any concrete benefit aside from the compiler syntax sugar!

@Eilon
Copy link
Member Author

Eilon commented May 28, 2022

Anyway, this is hardly a big matter, I just don't like extension methods on object 😁

@Dreamescaper
Copy link
Contributor

According to SharpLab, it compiles to smth like this:

    [CompilerGenerated]
    internal unsafe static Func<object> <<Main>$>g__Del4|0_3(object o)
    {
        return new Func<object>(o, (nint)(delegate*<object, object>)(&Helper.This));
    }

But I cannot write such code manually, I can't even find Func constructor with two parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mobileblazorbindings Experimental Mobile Bindings for Blazor
Projects
None yet
Development

No branches or pull requests

2 participants