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

Add support for non-string constants #150

Open
kzu opened this issue Jan 1, 2023 Discussed in #103 · 4 comments
Open

Add support for non-string constants #150

kzu opened this issue Jan 1, 2023 Discussed in #103 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kzu
Copy link
Collaborator

kzu commented Jan 1, 2023

Discussed in #103

Originally posted by rdeago May 19, 2022
I'll let code speak for me:

  <PropertyGroup>

    <!-- This still works, of course -->
    <Constant Name="Greeting" Value="Howdy!" />

    <!-- Constant type can be specified -->
    <Constant Name="Foo" Type="string" Value="Bar" />

    <!-- Int32, Integer (for the sake of VB projects) and int are all valid and map to System.Int32 -->
    <Constant Name="Answer" Type="int" Value="42" />

    <!-- Other numeric types work similarly -->
    <Constant Name="LongAnswer" Type="Int64" Value="42" />

    <!-- DateTime (and maybe TimeSpan, DateOnly, TimeOnly) may be supported too -->
    <Constant Name="BuildTime" Type="DateTime" Value="$([System.DateTime]::Now.ToString("O"))" />

  </PropertyGroup>

If this looks interesting, I can have a PR ready in a few days.

@kzu kzu added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 1, 2023
@kzu
Copy link
Collaborator Author

kzu commented Jan 1, 2023

Hopefully now that we have incremental generators everywhere, @rdeago can send a PR? 💯

@justinwritescode
Copy link

justinwritescode commented Jan 6, 2023

Can't have a const DateTime....it's dumb, but that's the way it is!

@kzu
Copy link
Collaborator Author

kzu commented Feb 6, 2023

Yeah, the generator should be smart about what can be emitted as a constant vs static read only

@kzu
Copy link
Collaborator Author

kzu commented Feb 21, 2023

I guess I'll have to work on this myself, since @rdeago hasn't sent a PR yet 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants