Skip to content

Commit

Permalink
Merge pull request #14 from westermo/support-netstandard
Browse files Browse the repository at this point in the history
Move to netstandard 2.0
  • Loading branch information
carl-andersson-at-westermo authored Apr 30, 2024
2 parents 3a6ba07 + b979433 commit 57943a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>FactoryGenerator</RootNamespace>
<LangVersion>latest</LangVersion>
</PropertyGroup>

</Project>
10 changes: 4 additions & 6 deletions FactoryGenerator.Attributes/IContainer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace FactoryGenerator;
#nullable enable
Expand All @@ -9,13 +7,13 @@ public interface ILifetimeScope : IDisposable
T Resolve<T>();
object Resolve(Type type);

bool TryResolve(Type type, [NotNullWhen(true)] out object? resolved);
bool TryResolve(Type type, out object? resolved);


bool TryResolve<T>([NotNullWhen(true)] out T? resolved);
bool TryResolve<T>(out T? resolved);

bool IsRegistered(Type type) => TryResolve(type, out _);
bool IsRegistered<T>() => IsRegistered(typeof(T));
bool IsRegistered(Type type);
bool IsRegistered<T>();
public ILifetimeScope BeginLifetimeScope();
}

Expand Down
12 changes: 11 additions & 1 deletion FactoryGenerator/FactoryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public bool TryResolve<T>(out T resolved)
resolved = default;
return false;
}}
public bool IsRegistered(Type type)
{{
return m_lookup.ContainsKey(type);
}}
public bool IsRegistered<T>() => IsRegistered(typeof(T));
}}";

var booleans = dataInjections.Select(inj => inj.BooleanInjection).Where(b => b is not null)
Expand Down Expand Up @@ -452,6 +457,11 @@ public bool TryResolve<T>(out T resolved)
resolved = default;
return false;
}}
public bool IsRegistered(Type type)
{{
return m_lookup.ContainsKey(type);
}}
public bool IsRegistered<T>() => IsRegistered(typeof(T));
}}
";
yield return Constructor(usingStatements, constructorFields,
Expand All @@ -469,7 +479,7 @@ private static void CheckForCycles(ImmutableArray<Injection> dataInjections)
foreach (var injection in dataInjections)
{
//Methods can sort themselves out, and may include logic that makes it unsuitable to cycle-detect.
if(injection.Lambda != null) continue;
if (injection.Lambda != null) continue;
var node = new List<INamedTypeSymbol>();
foreach (var iface in injection.Interfaces)
{
Expand Down

0 comments on commit 57943a1

Please sign in to comment.