-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCsParameterDefaultValueExtensions.cs
More file actions
56 lines (44 loc) · 1.9 KB
/
CsParameterDefaultValueExtensions.cs
File metadata and controls
56 lines (44 loc) · 1.9 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
55
56
//*****************************************************************************
//* Code Factory SDK
//* Copyright (c) 2022 CodeFactory, LLC
//*****************************************************************************
using CodeFactory.DotNet;
using CodeFactory.DotNet.CSharp;
using CodeFactory.DotNet.CSharp.FormattedSyntax;
namespace CodeFactory.Formatting.CSharp
{
/// <summary>
/// Extensions class that provides common automation tasks rolled up under standard extension methods that support the <see cref="CsParameterDefaultValue"/> model.
/// </summary>
public static class CsParameterDefaultValueExtensions
{
/// <summary>
/// Extension method that generates the default value syntax for a parameter in the C# language.
/// </summary>
/// <param name="source">The target default value to format.</param>
/// <param name="type">The target type of the value to be formatted.</param>
/// <returns>The fully formatted syntax for the default value or null if data was missing.</returns>
public static string CSharpFormatParameterDefaultValue(this CsParameterDefaultValue source, CsType type)
{
if (source == null) return null;
if (type == null) return null;
string result = null;
switch (source.ValueType)
{
case ParameterDefaultValueType.Value:
result = type.CSharpFormatValueSyntax(source.Value);
break;
case ParameterDefaultValueType.DefaultKeyWord:
result = Keywords.Default;
break;
case ParameterDefaultValueType.NullKeyword:
result = Keywords.Null;
break;
default:
result = null;
break;
}
return result;
}
}
}