From d3e0a3726106c1c83c8021c30d07b012c2ebebdb Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Fri, 27 Sep 2024 02:27:12 -0300 Subject: [PATCH] Remove doc on DateTime being invalid Since when using public visibility, it can be valid since they would be static readonly props with a lambda now. For example, the following now works just fine: ```xml ``` And generates: ```csharp public static TimeSpan TypedTimeSpan => TimeSpan.FromSeconds(5); ``` --- src/ThisAssembly.Constants/readme.md | 3 +-- src/ThisAssembly.Tests/Tests.cs | 4 ++++ src/ThisAssembly.Tests/ThisAssembly.Tests.csproj | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ThisAssembly.Constants/readme.md b/src/ThisAssembly.Constants/readme.md index 18145709..8d8cb0b3 100644 --- a/src/ThisAssembly.Constants/readme.md +++ b/src/ThisAssembly.Constants/readme.md @@ -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+). diff --git a/src/ThisAssembly.Tests/Tests.cs b/src/ThisAssembly.Tests/Tests.cs index 0e227a0d..8d69e171 100644 --- a/src/ThisAssembly.Tests/Tests.cs +++ b/src/ThisAssembly.Tests/Tests.cs @@ -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")); diff --git a/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj b/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj index 5804cd5c..4a7fccfc 100644 --- a/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj +++ b/src/ThisAssembly.Tests/ThisAssembly.Tests.csproj @@ -17,7 +17,7 @@ // Some comments too. net472 ThisAssemblyTests - true + CS0618;CS8981;TA100;$(NoWarn) false @@ -82,6 +82,8 @@ + +