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

Remove doc on DateTime being invalid #402

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ThisAssembly.Constants/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public HttpClient CreateHttpClient(string name, int? timeout = default)
Note how the constant is typed to `int` as specified in the `Type` attribute in MSBuild.
The generated code uses the specified `Type` as-is, as well as the `Value` attribute in that
case, so it's up to the user to ensure they match and result in valid C# code. For example,
you can emit a boolean, long, double, etc., but a `DateTime` wouldn't be a valid constant even
if you set the `Value` to `DateTime.Now`. If no type is provided, `string` is assumed. Values
you can emit a boolean, long, double, etc.. If no type is provided, `string` is assumed. Values
can also be multi-line and will use [C# raw string literals](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string)
if supported by the target language version (11+).

Expand Down
4 changes: 4 additions & 0 deletions src/ThisAssembly.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void CanUseTypedBoolConstant()
public void CanUseTypedDoubleConstant()
=> Assert.Equal(1.23, ThisAssembly.Constants.TypedDouble);

[Fact]
public void CanUseTypedTimeSpanStaticProp()
=> Assert.Equal(TimeSpan.FromSeconds(5), ThisAssembly.Constants.TypedTimeSpan);

[Fact]
public void CanUseFileConstants()
=> Assert.Equal(ThisAssembly.Constants.Content.Docs.License, Path.Combine("Content", "Docs", "License.md"));
Expand Down
4 changes: 3 additions & 1 deletion src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Some comments too.</Description>
<TargetFramework Condition="'$(BuildingInsideVisualStudio)' == 'true'">net472</TargetFramework>
<RootNamespace>ThisAssemblyTests</RootNamespace>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<!--<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>-->
<NoWarn>CS0618;CS8981;TA100;$(NoWarn)</NoWarn>
<PackageScribanIncludeSource>false</PackageScribanIncludeSource>
</PropertyGroup>
Expand Down Expand Up @@ -82,6 +82,8 @@
<Constant Include="TypedLong" Value="123" Type="long" />
<Constant Include="TypedDouble" Value="1.23" Type="double" />
<Constant Include="TypedBoolean" Value="true" Type="bool" />
<!-- Since use use ThisAssemblyVisibility=public, this will turn into a static readonly prop with a lambda, so it works -->
<Constant Include="TypedTimeSpan" Value="TimeSpan.FromSeconds(5)" Type="TimeSpan" />
</ItemGroup>

<ItemGroup>
Expand Down