Skip to content

Commit

Permalink
introduce ClassSyntaxFactoryBase.ResolveStaticGlobal() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sholtee committed Apr 24, 2022
1 parent d5a8339 commit 6f46993
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/********************************************************************************
* ClassSyntaxFactoryBase.Field.cs *
* *
* Author: Denes Solti *
********************************************************************************/
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace Solti.Utils.Proxy.Internals
{
internal partial class ClassSyntaxFactoryBase
{
/// <summary>
/// private static readonly System.Object paramName [= ...];
/// </summary>
#if DEBUG
internal
#endif
protected FieldDeclarationSyntax ResolveStaticGlobal(ITypeInfo type, string name, ExpressionSyntax? initializer = null)
{
VariableDeclaratorSyntax declarator = VariableDeclarator
(
identifier: Identifier(name)
);

if (initializer is not null) declarator = declarator.WithInitializer
(
initializer: EqualsValueClause
(
initializer
)
);

return FieldDeclaration
(
declaration: VariableDeclaration
(
type: ResolveType(type),
variables: SingletonSeparatedList(declarator)
)
)
.WithModifiers
(
TokenList
(
new[]
{
Token(SyntaxKind.PrivateKeyword),
Token(SyntaxKind.StaticKeyword),
Token(SyntaxKind.ReadOnlyKeyword)
}
)
);
}
}
}

0 comments on commit 6f46993

Please sign in to comment.