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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
tkym
January 24, 2026
Programming
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
950
すこし踏み込む CancellationToken
htkym
2
1.7k
AIの中の人になってみる
htkym
0
220
今さら聞けない .NET CLI
htkym
0
270
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
170
今さら聞けないCancellationToken
htkym
0
330
GitHub Copilot CLIのいいところ
htkym
2
1.5k
GitHubCopilotCLIをはじめよう.pdf
htkym
0
430
RoslynAnalyzerをつかってみよう
htkym
0
1.3k
Other Decks in Programming
See All in Programming
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
470
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
530
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
320
contenteditable と日本語入力に向き合う
colorful12
0
180
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
1
430
dotNET_vulnclicker_intro.pdf
deka_morita
0
130
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
phperだってパンチカードでコーディングしたい
o0h
PRO
0
260
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
320
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
470
Are APIs Still Relevant in the AI Era?
soyuka
0
450
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
My Coaching Mixtape
mlcsv
0
350
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Designing Experiences People Love
moore
143
24k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
930
From π to Pie charts
rasagy
1
390
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
610
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