Format text in file - Windows Forms
I'm creating a class creation automator, basically a Windows Forms that has components like the class name, and the properties that the user wants to insert, when he clicks on add class, a savefiledialog opens. The problem is that I need help formatting the text in the class file, I tested with String builder but it didn't work well, because I can't indent the keys, or can I? I'm a layman on the subject so any help or path to follow will help a lot. Thank you.

5 Replies

Well, this is entirely a case of unnecessary whitespace before
internal
, that first {
, and a spurious closing brace.
(Or did you mean to use block-scoped namespaces, instead of the newer and better file-scoped namespaces)?
If you intend to do anything nontrivial with this, I would suggest writing a class that wraps StringBuilder and tracks the indent level.
You'd have a StartBlock method that bumps the indent level, and an EndBlock that decreases it.
Then your various Append methods would insert the number of spaces (or tabs) corresponding to that indent level before inserting the text you passed in.Okay, I'm kind of a layman on this subject, can you send me a website or a video that explains this better? Or if it's not, a technical term for me to look up, can I see a step by step? Thanks!
something like
which you can use like to get
@Lorenzo
Optionally, you could put the writing of { and } into StartBlock and EndBlock.
Ok thanks for the feedback and for your patience!