From 6c848cd97d2d6bdc9bf98ddbd6036f8cb3ddea7e Mon Sep 17 00:00:00 2001 From: almaraubel Date: Wed, 3 Jul 2024 11:08:20 +0200 Subject: [PATCH] Update CSharpFunctionalExtensions package and modify conditionals The CSharpFunctionalExtensions package has been updated to version 2.42.5 across all projects. Additionally, some conditional statements in Class1.cs have been modified for better interpretation and control flow, improving code readability and performance. Additional functionality has been added to the Class1 with the insertion of Test2() and CombinedCheckExample() methods. --- ...ctionalExtensions.Analyzers.Samples.csproj | 2 +- .../Class1.cs | 38 ++++++++++++++++--- ...unctionalExtensions.Analyzers.Tests.csproj | 2 +- ...SharpFunctionalExtensions.Analyzers.csproj | 2 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/CSharpFunctionalExtensions.Analyzers.Samples/CSharpFunctionalExtensions.Analyzers.Samples.csproj b/CSharpFunctionalExtensions.Analyzers.Samples/CSharpFunctionalExtensions.Analyzers.Samples.csproj index 8c7870b..d068567 100644 --- a/CSharpFunctionalExtensions.Analyzers.Samples/CSharpFunctionalExtensions.Analyzers.Samples.csproj +++ b/CSharpFunctionalExtensions.Analyzers.Samples/CSharpFunctionalExtensions.Analyzers.Samples.csproj @@ -15,7 +15,7 @@ OutputItemType="Analyzer" ReferenceOutputAssembly="false"/> - + diff --git a/CSharpFunctionalExtensions.Analyzers.Samples/Class1.cs b/CSharpFunctionalExtensions.Analyzers.Samples/Class1.cs index 0603f6c..3c89b88 100644 --- a/CSharpFunctionalExtensions.Analyzers.Samples/Class1.cs +++ b/CSharpFunctionalExtensions.Analyzers.Samples/Class1.cs @@ -44,22 +44,29 @@ public int Test() { var y = Result.Success(1); - if (y.IsFailure) return y.Value; - + if (!y.IsSuccess || y.Value > 0 ) return 0; + return 1; } + public int Test2() + { + var y = Result.Success(1); + var x = y.IsSuccess ? y.Value : 0; + var foo = y.Value; + return y.IsFailure ? 0 : y.Value; + } public int PatternMatching() { var result = Result.Success(1); var id = result switch { - { IsSuccess: true }=> result.Value, - { Error: "eror" } => 0, + { IsSuccess: true, Value: 1 }=> result.Value, + { Error: "eror", Value: 1 } => 0, _ => throw new ArgumentOutOfRangeException() }; - var x = (result.IsFailure)? 0: result.Value; + var x = result.IsFailure? 0: result.Value; switch (result.IsSuccess) { case true: @@ -75,10 +82,29 @@ public void UsingStatementExample() { var result = Result.Success(1); if (result.IsFailure) return; - + //var resultMessage = !result.IsSuccess ? $"{result.Value} success." : "Failed."; using (var streamWriter = new StreamWriter("filePath")) { streamWriter.Write(result.Value); } } + + public void CombinedCheckExample() + { + var result = Result.Success(1); + //if (result.IsFailure || result.Value == 1 ) return; + if (result is { IsSuccess: true, Value: > 1 }) + { + Console.WriteLine("foo" + result.Value); + } + + // if (result.IsSuccess && result.Value == 1) + // { + // Console.WriteLine("foo" + result.Value); + // } + + + } + + } diff --git a/CSharpFunctionalExtensions.Analyzers.Tests/CSharpFunctionalExtensions.Analyzers.Tests.csproj b/CSharpFunctionalExtensions.Analyzers.Tests/CSharpFunctionalExtensions.Analyzers.Tests.csproj index 8fcab80..dafd118 100644 --- a/CSharpFunctionalExtensions.Analyzers.Tests/CSharpFunctionalExtensions.Analyzers.Tests.csproj +++ b/CSharpFunctionalExtensions.Analyzers.Tests/CSharpFunctionalExtensions.Analyzers.Tests.csproj @@ -22,7 +22,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/CSharpFunctionalExtensions.Analyzers/CSharpFunctionalExtensions.Analyzers.csproj b/CSharpFunctionalExtensions.Analyzers/CSharpFunctionalExtensions.Analyzers.csproj index 6fb8c46..0a87bb3 100644 --- a/CSharpFunctionalExtensions.Analyzers/CSharpFunctionalExtensions.Analyzers.csproj +++ b/CSharpFunctionalExtensions.Analyzers/CSharpFunctionalExtensions.Analyzers.csproj @@ -36,7 +36,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive