nameof in attribute produces empty string

210 views Asked by At

Right now I'm developing INotifyPropertyChanged source generator (to study generators) and stumbled at weird bug(?). When attribute uses nameof to reference generated property corresponding AttributeData.ConstructorArguments contains empty string instead of property name.

[AutoNotify]
partial class Sample
{
    string _someProp;
    
    [NotifyDependsOn(nameof(SomeProp), nameof(_someProp))]
    public string Dependent => _str;

    public string Foo() => SomeProp; // added by generator
}

SomeProp is generated property, which is not added to source at the moment. Everything works if member is user-defined. This code compiles.

enter image description here

  1. Is it bug in compiler or it's by design?
  2. What is best way to workaround this? Go down from semantic model to syntax or do something else?
0

There are 0 answers