How do you write a code in C# to split the list [a, b, c, d, e, f, g, h]
into sublists [a, b, c], [d, e, f], [g, h]
each with three elements and the last with less than three? The most popular answer is the following LINQ.
Category: C#
The dotnet format command and StyleCop.Analyzers
This article shows how to use the dotnet format command to format your source code according to a specific coding style. The article discusses its limitations and how to overcome them by introducing StyleCop.Analyzers. It also mentions the way to apply StyleCop.Analyzers to all projects in a solution.
Continue reading "The dotnet format command and StyleCop.Analyzers"Equality Comparison of Floating-Point Numbers in C# (and Others)
tl;dr
You should compare two floating-point numbers for equality in C# as follows:
tolerance
must be much larger than double.Epsilon
.
Implementing a System Tray App with WPF and MVVM
This article illustrates the implementation of a system tray application with WPF and the MVVM pattern. The full source code is in the GitHub repository.
The implementation has two distinctive points. First, it does not use notable WPF NotifyIcon because the license, CPOL, isn't compatible with any OSS licenses. Then, the implementation obeys the MVVM pattern and has no code behind.
Continue reading "Implementing a System Tray App with WPF and MVVM"Migrate To MahApps.Metro 2.x
This article shows the migration steps from MahApps 1.3.0 to 2.4.3 for BurageSnap, a screen capture tool. BurageSnap uses MahApps to realize its small footprint, as shown below.
Continue reading "Migrate To MahApps.Metro 2.x"Quite Simple Memory Pool in C#
This article shows a quite simple memory pool to make a thread-unsafe library thread-safe without performance degradation in single-threaded programs. Same as the previous article, this article is about DynaJson.
Thread-safety requires overhead to allocate an instance by each invocation to isolate data being altered. Unless thread-safety is required, we can use a static class or a singleton to eliminate any additional allocation.
Continue reading "Quite Simple Memory Pool in C#"NaN Boxing in C#
This article shows how to use NaN Boxing to improve the performance of a JSON parser for C# named DynaJson.
About DynaJson
DynaJson is a fast JSON parser for C# compatible with DynamicJson. I feel DynamicJson is very useful but lack sufficient performance, so I developed a faster replacement.
Continue reading "NaN Boxing in C#"How to Make JSON Parser Strict
I developed a JSON Parser for C# named DynaJson. It is very strict to the standard of RFC 8259. It accepts all conformant and rejects all non-conformant JSONs except for two exceptions.
One exception is trailing-commas. Another is leading 0 in numbers, for example, 02
and -02
. The former is for practicality. The latter is for compatibility with DynamicJson.
JSON's grammar is simple, but carelessly implemented parsers don't accept all conformant and not reject non-conformant JSONs. An excellent article of Parsing JSON is a Minefield shows where mines are in implementing JSON parsers.
Continue reading "How to Make JSON Parser Strict"