TaoK/PoorMansTSqlFormatter — pull request #85 by TimothyK (2012-11-29 06:33:29+00:00)
Title: TSqlStandardFormatterOptions

Tao,

Basically what I have done is separate out the Formatter Options and Formatter itself into 2 different classes.

I think this change makes it easier to add Options to the Formatter. The current version of TSqlStandardFormatter had a constructor of 13 parameters for all the various options. If I wanted to add a new option, then I'd have to add a parameter to this constructor. That would be a breaking change to the code base. All clients would have to add the new parameter if they were using that constructor when the got the latest code base.

Now the TSqlStandardFormatter class has a constructor that takes a TSqlStandardFormatterOptions parameter. This new class has properties that are equivalent to the old parameters. This is more maintainable because adding a new property to the class won't break any existing code.

The Tests were setting this options from the key value pairs embedded in the StandardFormatSql test file names (e.g. 14_CommentPositioning(TrailingCommas=True).txt). The new Options class has a constructor that supports this same config string format ("TrailingCommas=True"). The tests were using Reflection to set the options on the Formatter class. I've changed this to pass the config string to the Options constructor instead of using reflection.

Having the Options class support these Config Strings instead of relying on Reflection will make it easier to manage changes. The Options constructor can easily handle legacy option names if the need arises.

I didn't change the ISqlSettings interface or anything with how options are saved by the configuration screen. I haven't wrapped my head around how all that works yet, but I suspect ISqlSettings could probably be replaced with TSqlStandardFormatterOptions in the future. The data store could just store the serialized config string instead of managing all the individual options.

Let me know if you have any questions or want me to change anything.

Thanks,
Timothy Klenke

Disclaimer: I'm a total beginner with git/GitHub and I don't use C# that much in my day job.