Skip to content

Commit

Permalink
Only consider public constructors in FactoryAttribute.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasstich committed Nov 24, 2024
1 parent 8ee0eba commit 9e377d1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Moyou.Aspects/Moyou.Aspects.Factory/FactoryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ private static void HandleNonDefaultConstructor(IAspectBuilder<INamedType> build
string trimmedInterfaceName, INamedType primaryInterface)
{
IConstructor? constructor;
if (memberType.Constructors.Count == 1)
if (memberType.Constructors.Count(constructor => constructor.Accessibility == Accessibility.Public) == 1)
{
constructor = memberType.Constructors.Single();
constructor =
memberType.Constructors.Single(constructor => constructor.Accessibility == Accessibility.Public);
}
else
{
try
{
constructor =
memberType.Constructors.SingleOrDefault(ctor => ctor.HasAttribute<FactoryConstructorAttribute>());
memberType.Constructors.SingleOrDefault(ctor =>
ctor.HasAttribute<FactoryConstructorAttribute>() && ctor.Accessibility == Accessibility.Public);
}
catch (InvalidOperationException iox)

Check warning on line 82 in Moyou.Aspects/Moyou.Aspects.Factory/FactoryAttribute.cs

View workflow job for this annotation

GitHub Actions / Build and Test on ubuntu-latest with .NET Core 8.x

The variable 'iox' is declared but never used

Check warning on line 82 in Moyou.Aspects/Moyou.Aspects.Factory/FactoryAttribute.cs

View workflow job for this annotation

GitHub Actions / Build and Test on windows-latest with .NET Core 8.x

The variable 'iox' is declared but never used

Check warning on line 82 in Moyou.Aspects/Moyou.Aspects.Factory/FactoryAttribute.cs

View workflow job for this annotation

GitHub Actions / Build and Test on macos-latest with .NET Core 8.x

The variable 'iox' is declared but never used
{
Expand Down

0 comments on commit 9e377d1

Please sign in to comment.