BrandGhost
← Back to C# & .NET

Language Features

C# language feature deep dives, including Roslyn analyzers, UnsafeAccessor, and techniques for making reflection-heavy code safe under Native AOT.

Articles

Distributing Roslyn Analyzers as NuGet Packages in .NET

Distributing Roslyn Analyzers as NuGet Packages in .NET

Learn to package and distribute your roslyn analyzer nuget package with the right folder structure, metadata, versioning, and CI/CD automation in .NET 10.

Read the whole article

Build Your First Roslyn Analyzer in C#: Diagnostics and Code Fix Walkthrough

Build Your First Roslyn Analyzer in C#: Diagnostics and Code Fix Walkthrough

Build roslyn analyzer c# from scratch -- complete project setup, DiagnosticAnalyzer scaffold, CodeFixProvider implementation, debugging, and unit tests.

Read the whole article

When to Use Enum vs Constants in C#: Decision Guide

When to Use Enum vs Constants in C#: Decision Guide

Struggling with enum vs const in C#? This decision guide covers type safety, extensibility, serialization, and the enumeration class pattern to help you choose correctly.

Read the whole article

C# Enum Switch: Pattern Matching and Exhaustive Checks

C# Enum Switch: Pattern Matching and Exhaustive Checks

Learn how to use C# enum with switch expressions and pattern matching. Covers exhaustive checks, discard arms, tuple patterns, guard clauses, and compiler warnings.

Read the whole article

C# Enum to String: Conversion Patterns and Best Practices

C# Enum to String: Conversion Patterns and Best Practices

Learn every C# enum to string conversion pattern: ToString, Enum.GetName, JsonStringEnumConverter, custom display names, and parsing strings back to enums safely.

Read the whole article

How to Use Enum in C#: Declaration, Values, and Best Practices

How to Use Enum in C#: Declaration, Values, and Best Practices

Learn how to use enum in C# from scratch. Covers declaring enums, assigning values, casting, comparing, iterating, and the best practices every C# developer should follow.

Read the whole article

Testing C# Source Generators: A Practical Guide

Testing C# Source Generators: A Practical Guide

Learn how to test C# source generators with .NET 10. Complete guide covering Microsoft.CodeAnalysis.Testing, unit tests, snapshot testing with Verify, and CI integration.

Read the whole article

C# Source Generators vs Reflection: Which Should You Use?

C# Source Generators vs Reflection: Which Should You Use?

Compare C# source generators vs reflection in .NET 10. Understand performance differences, AOT compatibility, and when to choose source generators over runtime reflection.

Read the whole article

How to Create Your First C# Source Generator (Step-by-Step)

How to Create Your First C# Source Generator (Step-by-Step)

Learn how to create a C# source generator with .NET 10. Step-by-step guide covering project setup, IIncrementalGenerator implementation, and packaging.

Read the whole article

How C# Source Generators Work: The Roslyn Compilation Pipeline Explained

How C# Source Generators Work: The Roslyn Compilation Pipeline Explained

Learn exactly how C# source generators work inside the Roslyn compilation pipeline. Understand the two-phase compilation model, syntax providers, and incremental execution.

Read the whole article

C# Source Generators: A Complete Guide to Compile-Time Code Generation

C# Source Generators: A Complete Guide to Compile-Time Code Generation

Master C# source generators with this complete guide. Learn how compile-time code generation works in .NET 10, why it beats reflection, and how to get started.

Read the whole article

Iterator Benchmarks That Shocked With Unexpected Results

I wanted to create a follow-up post in my series on IEnumerables, iterators, and collections focusing on performance characteristics. When checking out the runtime performance and memory characteristics between these materialized collections and iterator benchmarks, I was very surprised! Check out this article for performance benchmark characteristics and some curious finds.

Read the whole article

Async EventHandlers - A Simple Safety Net to the Rescue

Async event handlers in C# are tricky: an async void event handler can swallow exceptions and crash your app. Use this simple safety-net pattern to handle them.

Read the whole article

An error has occurred. This application may no longer respond until reloaded. Reload