Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/AutoFactories.Tests/GenericFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,30 @@ public Person([FromFactory] IEqualityComparer<string?> comparer)
}
}
"""]);


[Fact]
public Task Static_Constructor_Is_Ignored()
=> CaptureAsync(
notes: ["Static constructor should be ignored and only instance constructor should generate factory method"],
verifySource: ["Widgets.WidgetFactory"],
source: ["""
using AutoFactories;

namespace Widgets
{
[AutoFactory]
public class Widget
{
static Widget()
{
}

public Widget(string name)
{
}
}
}
"""]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// -----------------------------| Notes |-----------------------------
// 1. Static constructor should be ignored and only instance constructor should generate factory method
// -------------------------------------------------------------------
#nullable enable
#pragma warning disable CS8019 // Unnecessary using directive.

using AutoFactories;


namespace Widgets
{
public partial class WidgetFactory : IWidgetFactory
{
public WidgetFactory()
{
}

/// <summary>
/// Creates a new instance of <see cref="Widgets.Widget"/>
/// </summary>
public global::Widgets.Widget Create(string name)
{
global::Widgets.Widget __result = new global::Widgets.Widget(
name);
return __result;
}
}
}
1 change: 1 addition & 0 deletions src/AutoFactories/Visitors/FactoryDeclartion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static FactoryViewModel Map(FactoryDeclaration declaration)
.ToList(),
Methods = declaration.Classes
.SelectMany(c => c.Constructors)
.Where(c => !c.IsStatic)
.Select(FactoryMethodViewModel.Map)
.ToList()
};
Expand Down
Loading