Skip to content

Commit

Permalink
working on IAkkaContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Dec 22, 2023
1 parent 8e4a7ca commit 0dc8512
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Akka.Analyzers/Utility/IAkkaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,47 @@
// </copyright>
// -----------------------------------------------------------------------

using Microsoft.CodeAnalysis;

namespace Akka.Analyzers;

/// <summary>
/// Provides information about the Akka.NET context (i.e. which libraries, which versions) in which the analyzer is running.
/// </summary>
public interface IAkkaContext
{
IAkkaCoreContext AkkaCoreContext { get; }
/// <summary>
/// Data about the core Akka.NET library.
/// </summary>
IAkkaCoreContext? AkkaCore { get; }

/// <summary>
/// Does the current compilation context even have Akka.NET installed?
/// </summary>
public bool HasAkkaInstalled { get; }
}

public class AkkaContext : IAkkaContext
{
private AkkaContext(){}

public IAkkaCoreContext? AkkaCore { get; private set; }
public bool HasAkkaInstalled => AkkaCore is not null;

public static AkkaContext? Get(
Compilation compilation,
Version? versionOverride = null)
{
// assert that compilation is not null
Guard.AssertIsNotNull(compilation);

var akkaCoreContext = AkkaCoreContext.Get(compilation, versionOverride);
if (akkaCoreContext is null)
return null;

return new AkkaContext
{
AkkaCore = AkkaCoreContext.Get(compilation, versionOverride)
};
}
}

0 comments on commit 0dc8512

Please sign in to comment.