String Format Diagnostic enables the validation of format strings at compile-time. Why Do This? Why? This turns a set of run-time exceptions into compile-time warnings! Supported Methods .ToString() on
.ParseExact on
.TryParseExact on
Note: The method overload which you can supply an array of format strings are not supported, C#Visual Basic Edit|Remove csharpvbSystem.Diagnostics.Debug.WriteLineSystem.Diagnostics.Trace.TraceErrorSystem.Diagnostics.Trace.TraceInformationSystem.Diagnostics.Trace.TraceWarningSystem.IO.TextWriter.WriteLineSystem.String.FormatSystem.Console,WriteSystem.Console.WritelineSystem.Text.StringBuilder.AppendFormatString.Format("{0}{2}", 0, 1);Console.Write("{0}{2}", 0, 1);Console.WriteLine("{0}{2}", 0, 1); String.Format("{0}{2}", 0, 1)Console.Write("{0}{2}", 0, 1)Console.WriteLine("{0}{2}", 0, 1) System.Diagnostics.Debug.WriteLine System.Diagnostics.Trace.TraceError System.Diagnostics.Trace.TraceInformation System.Diagnostics.Trace.TraceWarning System.IO.TextWriter.WriteLine System.String.Format System.Console,Write System.Console.Writeline System.Text.StringBuilder.AppendFormat String.Format("{0}{2}", 0, 1); Console.Write("{0}{2}", 0, 1); Console.WriteLine("{0}{2}", 0, 1); Example of Supported Validation Rules Currently it supports the following validation checks
Also gives information that the formatstring contains no argument index references. Eg {1} Format Argument of an hole is now validated against the type of the refered to object. The formatstring argument can be:-
Diagnostic available for both VB.net and C#.
VS2014 (ctp4) Note: These are beta releases, so bug report are very welcome. If you discover a format string thet is incorrect validated please file a bug report on the project site, as the validation rules applied are my intereptation of the available documentation. |