Lappa.Conventions
1.0.2
dotnet add package Lappa.Conventions --version 1.0.2
NuGet\Install-Package Lappa.Conventions -Version 1.0.2
<PackageReference Include="Lappa.Conventions" Version="1.0.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Lappa.Conventions" Version="1.0.2" />
<PackageReference Include="Lappa.Conventions"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Lappa.Conventions --version 1.0.2
#r "nuget: Lappa.Conventions, 1.0.2"
#:package Lappa.Conventions@1.0.2
#addin nuget:?package=Lappa.Conventions&version=1.0.2
#tool nuget:?package=Lappa.Conventions&version=1.0.2
Lappa.Conventions
Opinionated C# project defaults providing:
- Type aliases:
int32,int64,uint8,float16, etc. via global using directives - Implicit null checks: Use
if (obj)/if (!obj)instead of null checks (C# 14 / .NET 10+) - Analyzers + code fixes: Enforce consistent usage with auto-fixable warnings
Installation
<PackageReference Include="Lappa.Conventions" Version="1.0.2" PrivateAssets="all" />
The source generator injects the global usings and extensions, the analyzer enforces usage and default .editorconfig configuration is applied automatically.
What's included
Type aliases (generated automatically)
int32 count = 42; // instead of int count = 42;
int64 bigNumber = 100L; // instead of long bigNumber = 100L;
uint8 flags = 0xFF; // instead of byte flags = 0xFF;
float16 small = 1.5f; // instead of Half small = 1.5f;
All type mappings:
| Alias | C# Keyword | CLR Type |
|---|---|---|
int8 |
sbyte |
System.SByte |
int16 |
short |
System.Int16 |
int32 |
int |
System.Int32 |
int64 |
long |
System.Int64 |
int128 |
System.Int128 |
|
uint8 |
byte |
System.Byte |
uint16 |
ushort |
System.UInt16 |
uint32 |
uint |
System.UInt32 |
uint64 |
ulong |
System.UInt64 |
uint128 |
System.UInt128 |
|
float16 |
System.Half |
Implicit Null Check (.NET 10+ only)
Test obj = new Test();
// instead of if (obj != null)
if (obj)
{
obj.DoWork();
obj = null;
}
// instead of:if (obj == null)
if (!obj)
{
// Do stuff...
}
Analyzers
LACON001: Use type alias
Flags usage of built-in keywords (int, long, etc.) and CLR type names (System.Int32, etc.) when a type alias is available.
Severity: Error (default), configurable to warning or lower for less strict rules.
LACON002: Use implicit null check
Flags explicit null comparisons (obj != null, obj == null, obj is null, obj is not null) and suggests using implicit extension checks instead.
Severity: Warning (default), configurable.
Configuration
Severity can be changed if required. Override those in your .editorconfig:
[*.cs]
# Change severity (none | suggestion | warning | error)
dotnet_diagnostic.LACON001.severity = error
dotnet_diagnostic.LACON002.severity = warning
License
Copyright (c) Arctium. All rights reserved.
Learn more about Target Frameworks and .NET Standard.
This package has 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.