Skip to content

Commit

Permalink
State and result of methods switch/map can be a ref struct
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGerr committed Nov 18, 2024
1 parent 3abf4b1 commit d3133b5
Show file tree
Hide file tree
Showing 29 changed files with 2,096 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</RepositoryUrl>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<RootNamespace>Thinktecture</RootNamespace>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>13.0</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Import Condition=" exists('$(ParentPropsFile)') " Project="$(ParentPropsFile)" />

<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<TargetFramework>net9.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591;CA1052;CA1062;CA1303;CA1707;CA1801;CA2000;NU1903</NoWarn>
<IsPackable>false</IsPackable>
<ImplicitUsings>disable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.</Description>
<PackageTags>common;EntityFrameworkCore</PackageTags>
<DefineConstants>$(DefineConstants);COMPLEX_TYPES</DefineConstants>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>Extends Entity Framework Core to support some components from Thinktecture.Runtime.Extensions.</Description>
<PackageTags>common;EntityFrameworkCore</PackageTags>
<DefineConstants>$(DefineConstants);COMPLEX_TYPES</DefineConstants>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,17 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
_sb.Append(" = null");
}

_sb.Append(@")
_sb.Append(")");

if (withState)
{
_sb.Append(@"
#if NET9_0_OR_GREATER
where TState : allows ref struct
#endif");
}

_sb.Append(@"
{");

GenerateIndexBasedActionSwitchBody(withState, isPartially);
Expand Down Expand Up @@ -598,6 +608,17 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct");

if (withState)
{
_sb.Append(@"
where TState : allows ref struct");
}

_sb.Append(@"
#endif
{");

GenerateIndexBasedFuncSwitchBody(withState, isPartially);
Expand Down Expand Up @@ -723,6 +744,9 @@ private void GenerateMap(bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct
#endif
{");

GenerateIndexBasedMapSwitchBody(isPartially);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,17 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
_sb.Append(" = null");
}

_sb.Append(@")
_sb.Append(")");

if (withState)
{
_sb.Append(@"
#if NET9_0_OR_GREATER
where TState : allows ref struct
#endif");
}

_sb.Append(@"
{");

if (_state.Settings.IsValidatable)
Expand Down Expand Up @@ -554,6 +564,17 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct");

if (withState)
{
_sb.Append(@"
where TState : allows ref struct");
}

_sb.Append(@"
#endif
{");

if (_state.Settings.IsValidatable)
Expand Down Expand Up @@ -724,6 +745,9 @@ private void GenerateMap(bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct
#endif
{");

if (_state.Settings.IsValidatable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,17 @@ private void GenerateSwitchForAction(bool withState, bool isPartially)
_sb.Append(" = null");
}

_sb.Append(@")
_sb.Append(")");

if (withState)
{
_sb.Append(@"
#if NET9_0_OR_GREATER
where TState : allows ref struct
#endif");
}

_sb.Append(@"
{");

GenerateIndexBasedActionSwitchBody(withState, isPartially);
Expand Down Expand Up @@ -387,6 +397,17 @@ private void GenerateSwitchForFunc(bool withState, bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct");

if (withState)
{
_sb.Append(@"
where TState : allows ref struct");
}

_sb.Append(@"
#endif
{");

GenerateIndexBasedFuncSwitchBody(withState, isPartially);
Expand Down Expand Up @@ -499,6 +520,9 @@ private void GenerateMap(bool isPartially)
}

_sb.Append(@")
#if NET9_0_OR_GREATER
where TResult : allows ref struct
#endif
{");

GenerateIndexBasedMapSwitchBody(isPartially);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Source generators for Thinktecture.Runtime.Extensions.</Description>
<TargetFrameworks></TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageTags>sourcegenerator</PackageTags>
<NoWarn>$(NoWarn);CS1591;RS2008;NU5128</NoWarn>
Expand Down
3 changes: 3 additions & 0 deletions src/Thinktecture.Runtime.Extensions/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace Thinktecture;
/// </summary>
/// <typeparam name="T">The type of the parameter.</typeparam>
public readonly ref struct Argument<T>
#if NET9_0_OR_GREATER
where T : allows ref struct
#endif
{
/// <summary>
/// Indication whether the argument is set (explicitly).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<Description>Provides an easy way to implement Smart Enums and Value Objects.</Description>
<PackageTags>smart-enum;value-object;</PackageTags>
<TargetFramework></TargetFramework>
<TargetFrameworks>net7.0;net9.0;</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<NoWarn>$(NoWarn);CS1591;CA1707;NU1903;NETSDK1206;NU1904</NoWarn>
<RootNamespace>Thinktecture.Runtime.Tests</RootNamespace>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<TargetFramework></TargetFramework>
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<DefineConstants>$(DefineConstants);COMPLEX_TYPES</DefineConstants>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<DefineConstants>$(DefineConstants);COMPLEX_TYPES</DefineConstants>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit d3133b5

Please sign in to comment.