GuidFromStringAnalyzer is a small Roslyn analyzer that detects instantiations of
System.Guid
with a string literal:
new Guid("26B5DB35-C401-4DE3-B3D8-203FF9A0CA91");
and provides the Construct from integers
fix-it to change them to the more efficient constructor using integers:
new Guid(0x26B5DB35, 0xC401, 0x4DE3, 0xB3, 0xD8, 0x20, 0x3F, 0xF9, 0xA0, 0xCA, 0x91);
The latter is directly embedded into the resulting assembly as a simple byte-array and requires no run-time parsing of the GUID string. Roslyn currently does not optimize the string literals away on its own, see the relevant issue.
Download the GuidFromStringAnalyzer
Visual Studio extension from the
VS Marketplace.
Code licensed under the MIT License.