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

[Enhancement] Add Fody Weaver #170

Open
dansiegel opened this issue Jan 29, 2020 · 4 comments
Open

[Enhancement] Add Fody Weaver #170

dansiegel opened this issue Jan 29, 2020 · 4 comments

Comments

@dansiegel
Copy link

Description

As discussed on Twitch... A Fody Weaver for Comet should be added to make it easy to implement INotifyPropertyRead/INotifyPropertyChanged

@SparkieLabs
Copy link

Alternatively a Source Generator could be added. There's an INotifyPropertyChanged changed example here:

https://github.com/dotnet/roslyn-sdk/blob/master/samples/CSharp/SourceGenerators/SourceGeneratorSamples/AutoNotifyGenerator.cs

@dansiegel
Copy link
Author

dansiegel commented May 26, 2020

@sparkie108 it's always a good idea to use Source Generation when/where possible. That said IL weaving presents certain advantages. As an example here, let's look at a sample BindingObject. Obviously the goal here is to not have to be so verbose.

// No Magic
public class Song : BindingObject
{
    public string Title
    {
        get => GetProperty<string>();
        set => SetProperty(value);
    }
}

With Fody we'd be able to write something closer to:

// Using Fody
public class Song : BindingObject
{
    public string Title { get; set; }
}

The benefit here is that it's clear what our actual goals are with this, we want a public property called Title that has a getter and a setter. We just don't care about the verbosity that comes with what we actually are doing in the getter/setter. The negative here is working with IL is voodoo magic that will drive any remotely sane person, insane.

Now let's look at code Gen...

// Using Code Gen
public class Song : BindingObject
{
    [AutoNotify]
    private string title;
}

While IL weaving allows you to mutate code, Code Gen is an additive process only and cannot modify existing code in any shape way or form. What this ultimately means is that we could indeed generate the public properties here, however we would be left with a bunch of unused private fields, and ultimately it harms the readability since it is no longer clear what our actual intent is in having a public property named Title with a getter and setter.

@saint4eva
Copy link

I think the newly released Source Generator would be able to do the same thing?

@SimonCropp
Copy link

need any help with this?

does the https://github.com/Fody/PropertyChanged not work with comet OOTB? can i make changes to enable that?

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

No branches or pull requests

4 participants