-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathParameter.cs
More file actions
44 lines (38 loc) · 1.45 KB
/
Parameter.cs
File metadata and controls
44 lines (38 loc) · 1.45 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
using M31.FluentApi.Generator.Commons;
namespace M31.FluentApi.Generator.CodeBuilding;
internal class Parameter : ICode
{
internal Parameter(
string type,
string name,
string? defaultValue = null,
int? genericTypeParameterPosition = null,
ParameterAnnotations? parameterAnnotations = null)
{
Type = type;
Name = CSharpKeywords.IsCSharpKeyword(name) ? $"@{name}" : name;
DefaultValue = defaultValue;
GenericTypeParameterPosition = genericTypeParameterPosition;
ParameterAnnotations = parameterAnnotations;
}
internal Parameter WithoutDefaultValue()
{
return new Parameter(Type, Name, null, GenericTypeParameterPosition, ParameterAnnotations);
}
internal string Type { get; }
internal string Name { get; }
internal string? DefaultValue { get; }
internal ParameterAnnotations? ParameterAnnotations { get; }
internal int? GenericTypeParameterPosition { get; }
internal bool IsGenericParameter => GenericTypeParameterPosition.HasValue;
internal bool HasAnnotation(ParameterKinds parameterKinds)
{
return ParameterAnnotations != null && ParameterAnnotations.Contains(parameterKinds);
}
public CodeBuilder AppendCode(CodeBuilder codeBuilder)
{
return codeBuilder
.Append(ParameterAnnotations)
.Append(Type).Space().Append(Name).Append(() => $" = {DefaultValue}", DefaultValue != null);
}
}