Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SourceGeneratorのススメ
Search
tkym
January 24, 2026
Programming
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SourceGeneratorのススメ
tkym
January 24, 2026
More Decks by tkym
See All by tkym
GitHub Agentic Workflows を触ってみる
htkym
2
1k
すこし踏み込む CancellationToken
htkym
2
1.8k
AIの中の人になってみる
htkym
0
230
今さら聞けない .NET CLI
htkym
0
310
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
180
今さら聞けないCancellationToken
htkym
0
360
GitHub Copilot CLIのいいところ
htkym
2
1.6k
GitHubCopilotCLIをはじめよう.pdf
htkym
0
440
RoslynAnalyzerをつかってみよう
htkym
0
1.4k
Other Decks in Programming
See All in Programming
LLM 101
dalinaum
0
470
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
300
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
150
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
250
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
120
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
310
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
410
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.1k
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
720
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
280
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.4k
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Faster Mobile Websites
deanohume
310
32k
Claude Code のすすめ
schroneko
67
230k
Ruling the World: When Life Gets Gamed
codingconduct
0
430
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
30 Presentation Tips
portentint
PRO
1
460
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Balancing Empowerment & Direction
lara
6
1.4k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Transcript
Source Generatorのススメ FutureOne株式会社 高山博司
高山博司 ・ FutureOne株式会社 ・ C#/.NET/Blazor tkym @h_tkymx
Source Generator
メタプログラミング ・ 他のコードを生成、変更、または分析できるコードを記述すること ・ 下記のものは ”実行時”に機能する。 リフレクション プログラムの実行中に、型 の情報を取得したり、それを 利用して動的にインスタンス
を作ったりする. スクリプティング 属性 (Attributes) コンパイラやフレームワーク に対して「これはこういう扱 いをしてね」という追加情報 を伝える コンパイル時には決まってい ないメソッドやプロパティに 対して、実行時にアクセスす る.(dynamic 型など). Roslyn Scripting APIを使っ て、文字列としてのC#コード を実行時にコンパイル・実行 することも可能. 式木(Expression Tree) コード(処理ロジック)を、コ ンパイル後の命令ではなく 『データ構造(ツリー状)』とし て扱う
C# Source Generator .NET 5 で導入されたコンパイル時のメタプログラミングツール なにがいいの? ・ 開発中に実行 ・
実行時のパフォーマンスが向上 ・ 新しいC#ソースファイルを生成し,自動的に追加 ・ リフレクションを排除 ・ AOTコンパイルとツリーシェイキングを可能に
AOT: Ahead of Time Compilation (事前コンパイル) 実行時ではなくビルド時に機械語へ変換する技術 ・ パフォーマンス向上 ・
起動時間の短縮 ・ ツリーシェイキングによるデプロイサイズの縮小 ・ 実行時の評価やリフレクションが不要
ソースジェネレーター VS. 生成AI
LoggerMeessage - .NET 6
GeneratedRegex - .NET 7 (.NET 9でプロパティも可能に)
System.Text.Json - .NET 8
Blazor Form Validation - .NET 10
Source Generatorの設計原則 ・ 「追加」のみで「変更」はしない 既存のC#コードを書き換えることはできない コンパイルプロセスに参加し、新しいC#ソースコードを追加する役割 ・ パイプラインによる高速化 ビルド速度を落とさないよう、必要なデータだけを抽出・キャッシュする 入力(ソースやファイル)から必要な情報だけを取り出し、変更があった場合のみコード再生成
・ 完全な独立性 順序不同: ジェネレーター同士の実行順序は決まっていない 相互不干渉: 他のジェネレーターが作ったコードは見えないし、触れない どのジェネレーターも「ユーザーが書いたコード(と外部ファイル)」だけを入力とする ・副作用のない純粋な処理 同じ入力なら常に同じ出力を返す。 診断(エラーや警告)も出力可能だが、ビルドプロセスを汚染しないように設計する
Source Generatorの実装 .NET 5 / C# 9 .NET 6 /
C# 10
C#/VBのコンパイラのオープンソース実装 dotnet/roslyn: The Roslyn .NET compiler provides C# and Visual
Basic languages with rich code analysis APIs. Roslynとは?
Compiler as a Service C# コンパイラ IL
Compiler as a Service C# コンパイラ IL Syntax Tree 構文木
Demo
まとめ Source Generator ・ 反復作業の削減 ・ リフレクションの排除 ・ AOTが可能に ・
https://github.com/dotnet/roslyn/blob/main/docs/features/incremental- generators.cookbook.md