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
Modernizing iOS Apps
seyfoyun
0
150
Getting Started with Vibe Coding
miccheng
0
180
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
120
Seven New Principles of Software Engineering
yegor256
0
460
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
220
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
310
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
110
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
Next.js: The final boss of Web Performance
guaca
0
380
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
110
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
160
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
220
Featured
See All Featured
From π to Pie charts
rasagy
1
440
Building the Perfect Custom Keyboard
takai
2
950
A Soul's Torment
seathinner
8
3.9k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
760
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
60k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
510
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
660
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
Optimizing for Happiness
mojombo
378
71k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
570
Discover your Explorer Soul
emna__ayadi
2
1.3k
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