Closed dbuvid closed 9 months ago
Are you sure about that?
I have added unit test that shows there is no problem with handling default value for arguments.
Hmm, must be something I'm doing wrong -- I was attempting to write my own CLI but I determined just using the extension will meet my requirements.
I'm using the same C# custom functions for both the CLI and extension but this scenario works fine with the extension.
Unfortunately there are small discrepancies in the data obtained through Roslyn API, between CLI and VS extension. VS is doing perfect job in compiling solution, and getting exactly the same results even with the help of Buildalyzer is not easy.
An attribute with a signature with a default value argument, i.e. public SomeAttribute(string arg1, string arg2 = null)
With the usage
[Some("arg1Value"]
Causes an exception to be thrown when you attempt to access the Arguments property on the IAttribute model.
https://github.com/NeVeSpl/NTypewriter/blob/98fbb168afe3d394862b8bae299c8741853ac968/NTypewriter.CodeModel.Roslyn/Attribute.cs#L46C50-L46C70 is the root cause; defaulted arguments are not included in the ConstructorArguments array.
As a workaround I have just been explicitly passing these parameters in the necessary attributes.