Skip to content

Commit

Permalink
Update CSharpFunctionalExtensions package and modify conditionals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlmarAubel committed Jul 3, 2024
1 parent 6ea29e6 commit 6c848cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.41.0" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.42.5" />
</ItemGroup>

</Project>
38 changes: 32 additions & 6 deletions CSharpFunctionalExtensions.Analyzers.Samples/Class1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
// }


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.41.0" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.42.5" />
<PackageReference Include="Microsoft.CodeAnalysis.CodeFix.Testing" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.41.0">
<PackageReference Include="CSharpFunctionalExtensions" Version="2.42.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 6c848cd

Please sign in to comment.