-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathInterface.cs
More file actions
54 lines (45 loc) · 1.67 KB
/
Interface.cs
File metadata and controls
54 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ReSharper disable ParameterHidesMember
namespace M31.FluentApi.Generator.CodeBuilding;
internal class Interface : ICode
{
private readonly List<CommentedMethodSignature> methodSignatures;
private readonly List<string> baseInterfaces;
internal Interface(string accessModifier, string name)
{
AccessModifier = accessModifier;
Name = name;
methodSignatures = new List<CommentedMethodSignature>();
baseInterfaces = new List<string>();
}
internal string AccessModifier { get; }
internal string Name { get; }
internal IReadOnlyCollection<CommentedMethodSignature> MethodSignatures => methodSignatures;
internal IReadOnlyCollection<string> BaseInterfaces => baseInterfaces;
internal void AddMethodSignature(CommentedMethodSignature methodSignature)
{
if (!methodSignature.MethodSignature.IsStandaloneSignature)
{
throw new ArgumentException("Expected a stand-alone method signature.");
}
methodSignatures.Add(methodSignature);
}
internal void AddBaseInterface(string baseInterface)
{
baseInterfaces.Add(baseInterface);
}
internal void AddBaseInterfaces(IEnumerable<string> baseInterfaces)
{
this.baseInterfaces.AddRange(baseInterfaces);
}
public CodeBuilder AppendCode(CodeBuilder codeBuilder)
{
return codeBuilder
.StartLine()
.Append($"{AccessModifier} interface {Name}")
.Append($" : {string.Join(", ", baseInterfaces)}", baseInterfaces.Count > 0)
.EndLine()
.OpenBlock()
.AppendWithBlankLines(methodSignatures)
.CloseBlock();
}
}