SharpDocx
                                
                                 SharpDocx copied to clipboard
                                
                                    SharpDocx copied to clipboard
                            
                            
                            
                        if statement deletes the entire paragraph
Hi,
I want to add a sentence to end of the paragraph with the following code, but when the statement is false the entire paragraph is deleted and the result is empty. If the statement is true there is no problem. Everything works as expected.
This is a paragraph. <% if (false) { %> The entire paragraph will be deleted. <% } %>
If I to do so with the Write method there is no problem, but in this case I am losing the formatting option.
This is a paragraph. <% if (false) { Write("This won't be displayed."); } %>
You can’t use text blocks to conditionally display a part of a paragraph. It’s all or nothing. This makes the text block implementation much simpler. It's not very likely that this will change soon. However, it might also give some unexpected results, as you did notice.
I added a section 'Text block limitations' to the Tutorial, where this issue is explicitly mentioned.