dotgenie.MicrosoftStyleNamingAnalyzer
5.0.0
dotnet add package dotgenie.MicrosoftStyleNamingAnalyzer --version 5.0.0
NuGet\Install-Package dotgenie.MicrosoftStyleNamingAnalyzer -Version 5.0.0
<PackageReference Include="dotgenie.MicrosoftStyleNamingAnalyzer" Version="5.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="dotgenie.MicrosoftStyleNamingAnalyzer" Version="5.0.0" />
<PackageReference Include="dotgenie.MicrosoftStyleNamingAnalyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add dotgenie.MicrosoftStyleNamingAnalyzer --version 5.0.0
#r "nuget: dotgenie.MicrosoftStyleNamingAnalyzer, 5.0.0"
#:package dotgenie.MicrosoftStyleNamingAnalyzer@5.0.0
#addin nuget:?package=dotgenie.MicrosoftStyleNamingAnalyzer&version=5.0.0
#tool nuget:?package=dotgenie.MicrosoftStyleNamingAnalyzer&version=5.0.0
Microsoft Style Naming Analyzer
A comprehensive Roslyn analyzer that enforces Microsoft naming conventions for C# code. Automatically detects naming violations and provides intelligent correction suggestions with red squiggles in Visual Studio and VS Code.
🎯 Features
Comprehensive Naming Convention Enforcement
- Classes & Interfaces: PascalCase with proper I-prefix for interfaces
- Methods & Properties: PascalCase
- Variables, Fields & Parameters: camelCase
- Hungarian Notation Detection: Automatically suggests removing prefixes like
str,int,bln
Smart Corrections
- Converts
snake_casetoPascalCaseorcamelCaseas appropriate - Removes Hungarian notation prefixes (
strUserName→UserName) - Adds interface I-prefix when missing (
UserService→IUserService) - Provides exact correction suggestions in warning messages
🚀 Quick Start
Installation
dotnet add package dotgenie.MicrosoftStyleNamingAnalyzer
Usage
Once installed, the analyzer automatically runs during build and provides warnings for naming violations:
// ❌ Violations detected:
public class user_service // MSN001: Should be 'UserService'
{
public string user_name { get; set; } // MSN004: Should be 'UserName'
private int strAge; // MSN008: Should be 'age' (Hungarian removal + camelCase)
public void get_user_data(string User_ID) // MSN003 + MSN007: Method and parameter violations
{
string Local_Variable = ""; // MSN006: Should be 'localVariable'
}
}
// ✅ Corrected code:
public class UserService
{
public string UserName { get; set; }
private int age;
public void GetUserData(string userID)
{
string localVariable = "";
}
}
📋 Diagnostic Rules
| Rule ID | Description | Example |
|---|---|---|
| MSN001 | Class names must be PascalCase | user_class → UserClass |
| MSN002 | Interface names must start with 'I' and be PascalCase | userService → IUserService |
| MSN003 | Method names must be PascalCase | get_data() → GetData() |
| MSN004 | Property names must be PascalCase | user_name → UserName |
| MSN005 | Field names must be camelCase | User_Field → userField |
| MSN006 | Variable names must be camelCase | Local_Var → localVar |
| MSN007 | Parameter names must be camelCase | Input_Data → inputData |
| MSN008 | Remove Hungarian notation | strUserName → UserName |
🔧 Configuration
The analyzer works out-of-the-box with default Microsoft naming conventions. All rules are enabled by default and provide warnings (not errors) to maintain build compatibility.
Supported Hungarian Prefixes
str(string) → removedint,lng(integer) → removedflt,dbl,dec(decimal) → removedbln,bool(boolean) → removedobj(object) → removedarr,lst(array/list) → removeddic(dictionary) → removed
🎯 Why Use This Analyzer?
✅ Benefits
- Consistent Code Style: Enforces Microsoft naming conventions across your entire codebase
- Developer Productivity: Instant feedback with red squiggles and correction suggestions
- Code Quality: Improves readability and maintainability
- Team Alignment: Ensures all developers follow the same naming standards
- Legacy Code Cleanup: Identifies and suggests fixes for outdated Hungarian notation
🏢 Perfect For
- Enterprise applications requiring consistent naming
- Teams transitioning from other naming conventions
- Legacy codebases with Hungarian notation
- Open source projects following Microsoft guidelines
- Code reviews and quality gates
🛠️ Requirements
- .NET Standard 2.0 or higher
- Visual Studio 2019+ or VS Code with C# extension
- Roslyn Analyzers support
📝 Example Output
When you build your project, you'll see helpful warnings like:
warning MSN001: Class 'user_manager' should be 'UserManager' (PascalCase required)
warning MSN004: Property 'user_id' should be 'UserId' (PascalCase required)
warning MSN008: Remove Hungarian notation: 'strFirstName' should be 'FirstName'
🤝 Contributing
Found an issue or want to contribute? This analyzer is part of the DotGenie toolkit for improving C# code quality.
📄 License
MIT License - See LICENSE file for details.
Made with ❤️ by DotGenie - Helping developers write better C# code, one naming convention at a time.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.