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

Template processing fails when reading arguments from an Attribute that has arguments with default values (Roslyn project) #97

Closed
dbuvid opened this issue Nov 15, 2023 · 3 comments

Comments

@dbuvid
Copy link

dbuvid commented Nov 15, 2023

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.

NeVeSpl added a commit that referenced this issue Nov 15, 2023
@NeVeSpl
Copy link
Owner

NeVeSpl commented Nov 15, 2023

Are you sure about that?

I have added unit test that shows there is no problem with handling default value for arguments.

@dbuvid
Copy link
Author

dbuvid commented Nov 15, 2023

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.

@NeVeSpl
Copy link
Owner

NeVeSpl commented Nov 15, 2023

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.

@NeVeSpl NeVeSpl closed this as completed Feb 10, 2024
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

2 participants