Ejemplo n.º 1
0
        private static BlockSyntax AddLockStatement(
            this BlockSyntax blockSyntax,
            string lockObjectName,
            string fieldName,
            ExpressionSyntax fieldIdentifierName,
            ExpressionSyntax fieldAssignmentExpression)
        {
            var assignmentStatement = RoslynUtils.AssignmentExpression(fieldName, fieldAssignmentExpression);
            var fieldNullStatement  = RoslynUtils.CheckNullStatement(fieldName,
                                                                     assignmentStatement.ToStatement());

            var lockStat = RoslynUtils.LockStatement(
                SyntaxFactory.IdentifierName(lockObjectName),
                SyntaxFactory.Block(fieldNullStatement, SyntaxFactory.ReturnStatement(fieldIdentifierName))
                );

            return(blockSyntax.AddStatements(lockStat));
        }