@@ -21,7 +21,7 @@ public interface ICodeBuilder
21
21
/// <param name="content">Main body content/logic of the member</param>
22
22
string BuildMemberBlockFromPrototype ( ModuleBodyElementDeclaration declaration ,
23
23
string content = null ,
24
- string accessibility = null ,
24
+ Accessibility accessibility = Accessibility . Public ,
25
25
string newIdentifier = null ) ;
26
26
27
27
/// <summary>
@@ -35,37 +35,36 @@ string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declaration,
35
35
/// Generates a Property Get codeblock based on the prototype declaration
36
36
/// </summary>
37
37
/// <param name="prototype">DeclarationType with flags: Variable, Constant, UserDefinedTypeMember, or Function</param>
38
- /// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
39
- /// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value' unless otherwise specified</param>
38
+ /// <param name="content">Member body content. Null results in an empty body. Formatting is the responsibility of the caller</param>
40
39
bool TryBuildPropertyGetCodeBlock ( Declaration prototype ,
41
40
string propertyIdentifier ,
42
41
out string codeBlock ,
43
- string accessibility = null ,
42
+ Accessibility accessibility = Accessibility . Public ,
44
43
string content = null ) ;
45
44
46
45
/// <summary>
47
46
/// Generates a Property Let codeblock based on the prototype declaration
48
47
/// </summary>
49
48
/// <param name="prototype">DeclarationType with flags: Variable, Constant, UserDefinedTypeMember, or Function</param>
50
- /// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
51
- /// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value ' unless otherwise specified</param>
49
+ /// <param name="content">Member body content. Null results in an empty body. Formatting is the responsibility of the caller</param>
50
+ /// <param name="parameterIdentifier">Defaults to 'RHS ' unless otherwise specified</param>
52
51
bool TryBuildPropertyLetCodeBlock ( Declaration prototype ,
53
52
string propertyIdentifier ,
54
53
out string codeBlock ,
55
- string accessibility = null ,
54
+ Accessibility accessibility = Accessibility . Public ,
56
55
string content = null ,
57
56
string parameterIdentifier = null ) ;
58
57
59
58
/// <summary>
60
59
/// Generates a Property Set codeblock based on the prototype declaration
61
60
/// </summary>
62
61
/// <param name="prototype">DeclarationType with flags: Variable, Constant, UserDefinedTypeMember, or Function</param>
63
- /// <param name="content">Member body content. Formatting is the responsibility of the caller</param>
64
- /// <param name="parameterIdentifier">Defaults to '<paramref name="propertyIdentifier"/>Value ' unless otherwise specified</param>
62
+ /// <param name="content">Member body content. Null results in an empty body. Formatting is the responsibility of the caller</param>
63
+ /// <param name="parameterIdentifier">Defaults to 'RHS ' unless otherwise specified</param>
65
64
bool TryBuildPropertySetCodeBlock ( Declaration prototype ,
66
65
string propertyIdentifier ,
67
66
out string codeBlock ,
68
- string accessibility = null ,
67
+ Accessibility accessibility = Accessibility . Public ,
69
68
string content = null ,
70
69
string parameterIdentifier = null ) ;
71
70
@@ -82,15 +81,15 @@ bool TryBuildPropertySetCodeBlock(Declaration prototype,
82
81
/// Generates a <c>UserDefinedTypeMember</c> declaration expression based on the prototype declaration
83
82
/// </summary>
84
83
/// <param name="prototype">DeclarationType with flags: Variable, Constant, UserDefinedTypeMember, or Function</param>
85
- /// <param name="indentation">Defaults is 4 spaces</param>
84
+ /// <param name="indentation">If left null, 4 spaces of indentation are applied </param>
86
85
bool TryBuildUDTMemberDeclaration ( string identifier , Declaration prototype , out string declaration , string indentation = null ) ;
87
86
}
88
87
89
88
public class CodeBuilder : ICodeBuilder
90
89
{
91
90
public string BuildMemberBlockFromPrototype ( ModuleBodyElementDeclaration declaration ,
92
91
string content = null ,
93
- string accessibility = null ,
92
+ Accessibility accessibility = Accessibility . Public ,
94
93
string newIdentifier = null )
95
94
{
96
95
@@ -105,16 +104,16 @@ public string BuildMemberBlockFromPrototype(ModuleBodyElementDeclaration declara
105
104
return string . Concat ( elements ) ;
106
105
}
107
106
108
- public bool TryBuildPropertyGetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , string accessibility = null , string content = null )
107
+ public bool TryBuildPropertyGetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , Accessibility accessibility = Accessibility . Public , string content = null )
109
108
=> TryBuildPropertyBlockFromTarget ( prototype , DeclarationType . PropertyGet , propertyIdentifier , out codeBlock , accessibility , content ) ;
110
109
111
- public bool TryBuildPropertyLetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , string accessibility = null , string content = null , string parameterIdentifier = null )
110
+ public bool TryBuildPropertyLetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , Accessibility accessibility = Accessibility . Public , string content = null , string parameterIdentifier = null )
112
111
=> TryBuildPropertyBlockFromTarget ( prototype , DeclarationType . PropertyLet , propertyIdentifier , out codeBlock , accessibility , content , parameterIdentifier ) ;
113
112
114
- public bool TryBuildPropertySetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , string accessibility = null , string content = null , string parameterIdentifier = null )
113
+ public bool TryBuildPropertySetCodeBlock ( Declaration prototype , string propertyIdentifier , out string codeBlock , Accessibility accessibility = Accessibility . Public , string content = null , string parameterIdentifier = null )
115
114
=> TryBuildPropertyBlockFromTarget ( prototype , DeclarationType . PropertySet , propertyIdentifier , out codeBlock , accessibility , content , parameterIdentifier ) ;
116
115
117
- private bool TryBuildPropertyBlockFromTarget < T > ( T prototype , DeclarationType letSetGetType , string propertyIdentifier , out string codeBlock , string accessibility = null , string content = null , string parameterIdentifier = null ) where T : Declaration
116
+ private bool TryBuildPropertyBlockFromTarget < T > ( T prototype , DeclarationType letSetGetType , string propertyIdentifier , out string codeBlock , Accessibility accessibility , string content = null , string parameterIdentifier = null ) where T : Declaration
118
117
{
119
118
codeBlock = string . Empty ;
120
119
if ( ! letSetGetType . HasFlag ( DeclarationType . Property ) )
@@ -142,27 +141,23 @@ private bool TryBuildPropertyBlockFromTarget<T>(T prototype, DeclarationType let
142
141
var letSetParamExpression = $ "{ paramMechanism } { propertyValueParam } { asTypeClause } ";
143
142
144
143
codeBlock = letSetGetType . HasFlag ( DeclarationType . PropertyGet )
145
- ? string . Join ( Environment . NewLine , $ "{ accessibility ?? Tokens . Public } { TypeToken ( letSetGetType ) } { propertyIdentifier } () { asTypeClause } ", content , EndStatement ( letSetGetType ) )
146
- : string . Join ( Environment . NewLine , $ "{ accessibility ?? Tokens . Public } { TypeToken ( letSetGetType ) } { propertyIdentifier } ({ letSetParamExpression } )", content , EndStatement ( letSetGetType ) ) ;
144
+ ? string . Join ( Environment . NewLine , $ "{ AccessibilityToken ( accessibility ) } { TypeToken ( letSetGetType ) } { propertyIdentifier } () { asTypeClause } ", content , EndStatement ( letSetGetType ) )
145
+ : string . Join ( Environment . NewLine , $ "{ AccessibilityToken ( accessibility ) } { TypeToken ( letSetGetType ) } { propertyIdentifier } ({ letSetParamExpression } )", content , EndStatement ( letSetGetType ) ) ;
147
146
return true ;
148
147
}
149
148
150
149
public string ImprovedFullMemberSignature ( ModuleBodyElementDeclaration declaration )
151
- => ImprovedFullMemberSignatureInternal ( declaration ) ;
150
+ => ImprovedFullMemberSignatureInternal ( declaration , declaration . Accessibility ) ;
152
151
153
- private string ImprovedFullMemberSignatureInternal ( ModuleBodyElementDeclaration declaration , string accessibility = null , string newIdentifier = null )
152
+ private string ImprovedFullMemberSignatureInternal ( ModuleBodyElementDeclaration declaration , Accessibility accessibility , string newIdentifier = null )
154
153
{
155
- var accessibilityToken = declaration . Accessibility . Equals ( Accessibility . Implicit )
156
- ? Tokens . Public
157
- : $ "{ declaration . Accessibility . ToString ( ) } ";
158
-
159
154
var asTypeName = string . IsNullOrEmpty ( declaration . AsTypeName )
160
155
? string . Empty
161
156
: $ " { Tokens . As } { declaration . AsTypeName } ";
162
157
163
158
var elements = new List < string > ( )
164
159
{
165
- accessibility ?? accessibilityToken ,
160
+ AccessibilityToken ( accessibility ) ,
166
161
$ " { TypeToken ( declaration . DeclarationType ) } ",
167
162
newIdentifier ?? declaration . IdentifierName ,
168
163
$ "({ ImprovedArgumentList ( declaration ) } )",
@@ -297,6 +292,11 @@ private static string BuildUDTMemberDeclaration(string udtMemberIdentifier, Decl
297
292
return $ "{ indentation ?? " " } { identifierExpression } { Tokens . As } { prototype . AsTypeName } ";
298
293
}
299
294
295
+ private static string AccessibilityToken ( Accessibility accessibility )
296
+ => accessibility . Equals ( Accessibility . Implicit )
297
+ ? Tokens . Public
298
+ : $ "{ accessibility . ToString ( ) } ";
299
+
300
300
private static bool IsValidPrototypeDeclarationType ( DeclarationType declarationType )
301
301
{
302
302
return declarationType . HasFlag ( DeclarationType . Variable )
0 commit comments