Skip to content

Commit

Permalink
Update TinyHelpers to .NET 9.0 (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva authored Nov 22, 2024
2 parents a5990ae + 3ab2692 commit 2efb3f4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_prefer_system_threading_lock = true:suggestion

# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
NET_VERSION: '8.x'
NET_VERSION: '9.x'
PROJECT_NAME: src/TinyHelpers
PROJECT_FILE: TinyHelpers.csproj
RELEASE_NAME: TinyHelpers
Expand Down
5 changes: 5 additions & 0 deletions samples/TinyHelpers.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
new("Marco", "Minerva", "Taggia")
};

foreach (var personItem in people.WithIndex())
{

}

var distinctPeople = people.DistinctBy(p => new { p.FirstName, p.LastName });
// Extracts Marco Minerva and Andrea Bianchi
Console.WriteLine(distinctPeople);
Expand Down
11 changes: 10 additions & 1 deletion src/TinyHelpers/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;

namespace TinyHelpers.Extensions;
Expand Down Expand Up @@ -144,6 +145,10 @@ public static void Remove<TSource>(this ICollection<TSource> collection, Func<TS
/// <param name="source">The <see cref="IEnumerable{T}"/> to create an <see cref="IEnumerable{T}"/> of <see cref="TinyHelpers.WithIndex{TValue}"/> elements from.</param>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="TinyHelpers.WithIndex{TValue}"/> elements that contains projected elements from the input sequence.</returns>
/// <seealso cref="TinyHelpers.WithIndex{TValue}"/>
#if NET9_0_OR_GREATER
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The WithIndex() method is obsolete. Please use Index() instead.")]
#endif
public static IEnumerable<WithIndex<TSource>> WithIndex<TSource>(this IEnumerable<TSource> source) where TSource : class
=> source.Select((item, index) => new WithIndex<TSource>(item, index));

Expand All @@ -154,6 +159,10 @@ public static IEnumerable<WithIndex<TSource>> WithIndex<TSource>(this IEnumerabl
/// <param name="source">The <see cref="IQueryable{T}"/> to create an <see cref="IEnumerable{T}"/> of <see cref="TinyHelpers.WithIndex{TValue}"/> elements from.</param>
/// <returns>An <see cref="IQueryable{T}"/> of <see cref="TinyHelpers.WithIndex{TValue}"/> elements that contains projected elements from the input sequence.</returns>
/// <seealso cref="TinyHelpers.WithIndex{TValue}"/>
#if NET9_0_OR_GREATER
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The WithIndex() method is obsolete. Please use Index() instead.")]
#endif
public static IQueryable<WithIndex<TSource>> WithIndex<TSource>(this IQueryable<TSource> source) where TSource : class
=> source.Select((item, index) => new WithIndex<TSource>(item, index));

Expand Down
2 changes: 1 addition & 1 deletion src/TinyHelpers/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static IEnumerable<T> GetFlags<T>(this T @enum) where T : Enum

if (bits != 0L)
{
return Enumerable.Empty<T>();
return [];
}

if (Convert.ToInt64(@enum) != 0L)
Expand Down
8 changes: 7 additions & 1 deletion src/TinyHelpers/Models/WithIndex.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
namespace TinyHelpers;
using System.ComponentModel;

namespace TinyHelpers;

/// <summary>
/// Represents a generic object with its relative index within a collection.
/// </summary>
/// <typeparam name="TValue">The type of the object.</typeparam>
/// <seealso cref="Extensions.CollectionExtensions.WithIndex{TSource}(IEnumerable{TSource})"/>
#if NET9_0_OR_GREATER
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The WithIndex() method is obsolete. Please use Index() instead.")]
#endif
public readonly struct WithIndex<TValue> where TValue : class
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/TinyHelpers/TinyHelpers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/TinyHelpers/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "3.1",
"version": "3.2",
"publicReleaseRefSpec": [
"^refs/heads/master$" // we release out of master
],
Expand Down

0 comments on commit 2efb3f4

Please sign in to comment.