Skip to content

Commit cde5a75

Browse files
committed
FunctionSequence goes generic
1 parent 6136263 commit cde5a75

3 files changed

Lines changed: 23 additions & 71 deletions

File tree

src/NetArchTest.Rules/Assemblies/ITypes.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/NetArchTest.Rules/FunctionDelegates.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ internal static class FunctionDelegates
2626
/// <summary> The base delegate type used by every function. </summary>
2727
internal delegate IEnumerable<TypeSpec> FunctionDelegate<T>(IEnumerable<TypeSpec> input, T arg, bool condition);
2828

29-
30-
internal static FunctionDelegate<string> HaveName = delegate (IEnumerable<TypeSpec> input, string name, bool condition)
29+
30+
public static IEnumerable<TypeSpec> HaveName(IEnumerable<TypeSpec> input, string name, bool condition)
3131
{
3232
if (condition)
3333
{
@@ -37,7 +37,7 @@ internal static class FunctionDelegates
3737
{
3838
return input.Where(c => !c.Definition.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
3939
}
40-
};
40+
}
4141

4242
/// <summary> Function for matching a type name using a regular expression. </summary>
4343
internal static FunctionDelegate<string> HaveNameMatching = delegate (IEnumerable<TypeSpec> input, string pattern, bool condition)

src/NetArchTest.Rules/FunctionSequence.cs

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,26 @@ namespace NetArchTest.Rules
1010
/// </summary>
1111
internal sealed class FunctionSequence
1212
{
13-
private readonly List<List<IFunctionCall>> _groups;
13+
private readonly List<List<IFunctionCall>> groups;
1414

1515

16-
/// <summary>
17-
/// Initializes a new instance of the <see cref="FunctionSequence"/> class.
18-
/// </summary>
19-
internal FunctionSequence()
16+
public FunctionSequence()
2017
{
21-
_groups = new List<List<IFunctionCall>>();
22-
_groups.Add(new List<IFunctionCall>());
18+
groups = new List<List<IFunctionCall>>();
19+
groups.Add(new List<IFunctionCall>());
2320
}
2421

2522

26-
/// <summary>
27-
/// Adds a function call to the current list.
28-
/// </summary>
29-
internal void AddFunctionCall<T>(FunctionDelegates.FunctionDelegate<T> method, T value, bool condition)
23+
public void AddFunctionCall<T>(FunctionDelegates.FunctionDelegate<T> method, T value, bool condition)
3024
{
31-
_groups.Last().Add(new FunctionCall(method, value, condition));
25+
groups.Last().Add(new FunctionCall<T>(method, value, condition));
3226
}
33-
34-
/// <summary>
35-
/// Creates a new logical grouping of function calls.
36-
/// </summary>
37-
internal void CreateGroup()
27+
public void CreateGroup()
3828
{
39-
_groups.Add(new List<IFunctionCall>());
29+
groups.Add(new List<IFunctionCall>());
4030
}
4131

32+
4233
/// <summary>
4334
/// Executes all the function calls that have been specified.
4435
/// </summary>
@@ -60,7 +51,7 @@ private void MarkPassingTypes(IEnumerable<TypeSpec> inputTypes)
6051
{
6152
inputTypes.ForEach(x => x.IsSelected = false);
6253

63-
foreach (var group in _groups)
54+
foreach (var group in groups)
6455
{
6556
IEnumerable<TypeSpec> passingTypes = inputTypes;
6657

@@ -74,43 +65,26 @@ private void MarkPassingTypes(IEnumerable<TypeSpec> inputTypes)
7465
}
7566
}
7667

77-
/// <summary>
78-
/// Represents a single function call.
79-
/// </summary>
80-
internal class FunctionCall : IFunctionCall
68+
69+
internal class FunctionCall<T> : IFunctionCall
8170
{
82-
/// <summary>
83-
/// Initializes a new instance of the <see cref="FunctionCall"/> class.
84-
/// </summary>
85-
internal FunctionCall(Delegate func, object value, bool condition)
71+
public FunctionDelegates.FunctionDelegate<T> FunctionDelegate { get; }
72+
public T FunctionArgument { get; }
73+
public bool Condition { get; }
74+
75+
76+
public FunctionCall(FunctionDelegates.FunctionDelegate<T> func, T argument, bool condition)
8677
{
8778
this.FunctionDelegate = func;
88-
this.Value = value;
79+
this.FunctionArgument = argument;
8980
this.Condition = condition;
9081
}
9182

9283

9384
public IEnumerable<TypeSpec> Execute(IEnumerable<TypeSpec> inputTypes)
9485
{
95-
return FunctionDelegate.DynamicInvoke(inputTypes, Value, Condition) as IEnumerable<TypeSpec>;
86+
return FunctionDelegate(inputTypes, FunctionArgument, Condition);
9687
}
97-
98-
99-
/// <summary>
100-
/// A delegate for a function call.
101-
/// </summary>
102-
public Delegate FunctionDelegate { get; private set; }
103-
104-
/// <summary>
105-
/// The input value for the function call.
106-
/// </summary>
107-
public object Value { get; private set; }
108-
109-
/// <summary>
110-
/// The Condition to apply to the call - i.e. "is" or "is not".
111-
/// </summary>
112-
public bool Condition { get; private set; }
113-
11488
}
11589

11690
internal interface IFunctionCall

0 commit comments

Comments
 (0)