<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73" -->

---
title: Adding Properties with extension methods in C# 14
description: Exploring two unconventional, playful techniques to add properties to existing types via C# 14 extension methods. The first uses ConditionalWeakTable and...
canonical: https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Adding Properties with extension methods in C# 14 | daily.dev
og:description: Exploring two unconventional, playful techniques to add properties to existing types via C# 14 extension methods. The first uses ConditionalWeakTable and...
og:url: https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73
og:image: https://api.daily.dev/og/posts/AAQhTtS73.png
og:image:alt: Adding Properties with extension methods in C# 14
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding Properties with extension methods in C# 14

**[We Are .NET](https://daily.dev/sources/wearedotnet)** · 3 min read · 1 upvotes · 0 comments

## Summary

Exploring two unconventional, playful techniques to add properties to existing types via C# 14 extension methods. The first uses ConditionalWeakTable and StrongBox<T> to associate mutable state with objects without preventing garbage collection. The second abuses Unsafe.As and matching field layouts to create a shadow type (PersonPlus) that extension properties can read from, including a static-constructor trick to sanity-check the layout at runtime. Both approaches are explicitly framed as fun experiments rather than production-ready patterns.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://steven-giesel.com/blogPost/4368fcea-c922-403e-bb3b-6b4990eb36d2>

## Questions this post answers

### How can I add a property to an existing C# class without modifying its source code using extension methods?

Use a static ConditionalWeakTable keyed on the target instance, storing values wrapped in a StrongBox<T>. The extension block then defines a property whose getter and setter read and write through the table, for example an extension(Person person) block exposing a Nickname property. ConditionalWeakTable avoids extending object lifetimes the way a plain Dictionary would, and StrongBox lets you distinguish an unset value from one explicitly set to null.

_daily.dev surfaces patterns like this for developers exploring what C# 14 extension members can actually do._

### Why use ConditionalWeakTable instead of a Dictionary to attach extra data to an object in C#?

A Dictionary keeps a strong reference to every key, so all associated instances stay alive as long as an entry exists, even if nothing else references them, causing a memory leak. ConditionalWeakTable associates data with an object without preventing that object from being garbage collected, releasing the entry automatically once the key object is no longer referenced elsewhere.

_understanding these tradeoffs matters when daily.dev readers debug memory leaks tied to auxiliary object data._

## Similar posts on daily.dev

- [Extension Properties: C\# 14’s Game-Changer for Cleaner Code](https://daily.dev/posts/extension-properties-c-14-s-game-changer-for-cleaner-code-aawdgf4pc) · Telerik · 0 upvotes · 0 comments
- [The best new features of C\# 14](https://daily.dev/posts/the-best-new-features-of-c-14-6gsbbjwv4) · InfoWorld · 46 upvotes · 4 comments
- [C\# Extension Members](https://daily.dev/posts/c-extension-members-1anekbztp) · JetBrains · 18 upvotes · 1 comments
- [Adding static getter thanks to extensions](https://daily.dev/posts/adding-static-getter-thanks-to-extensions-rvnhzsfwz) · We Are .NET · 0 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Adding Properties with extension methods in C# 14","url":"https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73"},"datePublished":"2026-09-04T09:48:24.071Z","dateModified":"2026-09-14T08:47:54.156Z","description":"Exploring two unconventional, playful techniques to add properties to existing types via C# 14 extension methods. The first uses ConditionalWeakTable and...","image":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","thumbnailUrl":"https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001","isAccessibleForFree":true,"articleSection":"We Are .NET","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"We Are .NET","logo":"https://media.daily.dev/image/upload/s--BsnVOa3i--/f_auto/v1718347410/logos/wearedotnet","url":"https://daily.dev/sources/wearedotnet"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"We Are .NET","item":"https://daily.dev/sources/wearedotnet"},{"@type":"ListItem","position":3,"name":"Adding Properties with extension methods in C# 14"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/adding-properties-with-extension-methods-in-c-14-aaqhtts73#faq","mainEntity":[{"@type":"Question","name":"How can I add a property to an existing C# class without modifying its source code using extension methods?","acceptedAnswer":{"@type":"Answer","text":"Use a static ConditionalWeakTable keyed on the target instance, storing values wrapped in a StrongBox\u003cT\u003e. The extension block then defines a property whose getter and setter read and write through the table, for example an extension(Person person) block exposing a Nickname property. ConditionalWeakTable avoids extending object lifetimes the way a plain Dictionary would, and StrongBox lets you distinguish an unset value from one explicitly set to null. daily.dev surfaces patterns like this for developers exploring what C# 14 extension members can actually do."}},{"@type":"Question","name":"Why use ConditionalWeakTable instead of a Dictionary to attach extra data to an object in C#?","acceptedAnswer":{"@type":"Answer","text":"A Dictionary keeps a strong reference to every key, so all associated instances stay alive as long as an entry exists, even if nothing else references them, causing a memory leak. ConditionalWeakTable associates data with an object without preventing that object from being garbage collected, releasing the entry automatically once the key object is no longer referenced elsewhere. understanding these tradeoffs matters when daily.dev readers debug memory leaks tied to auxiliary object data."}}]}
```

