diff --git a/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs new file mode 100644 index 0000000..93c0e45 --- /dev/null +++ b/SRC/Private/SyntaxFactories/ClassSyntaxFactoryBase.Field.cs @@ -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 + { + /// + /// private static readonly System.Object paramName [= ...]; + /// + #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) + } + ) + ); + } + } +}