Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SourceGeneratorのマーカー属性問題について
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
tkym
February 28, 2026
Programming
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SourceGeneratorのマーカー属性問題について
tkym
February 28, 2026
More Decks by tkym
See All by tkym
今さら聞けない .NET CLI
htkym
0
7
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
100
今さら聞けないCancellationToken
htkym
0
250
GitHub Copilot CLIのいいところ
htkym
2
1.4k
GitHubCopilotCLIをはじめよう.pdf
htkym
0
380
RoslynAnalyzerをつかってみよう
htkym
0
840
SourceGeneratorのススメ
htkym
0
930
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
230
.NET 10のEntity Framework Coreの新機能
htkym
0
1.1k
Other Decks in Programming
See All in Programming
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
540
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
430
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
520
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
830
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
200
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
230
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.2k
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
180
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
120
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.7k
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
430
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
Statistics for Hackers
jakevdp
799
230k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
A designer walks into a library…
pauljervisheath
211
24k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Paper Plane
katiecoart
PRO
2
52k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
410
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Transcript
Source Generatorの マーカー属性問題について 2026/02/28 .NETラボ勉強会2月
高山博司 ・ FutureOne株式会社 ・ C#/.NET/Blazor tkym @h_tkymx
Source Generator
C# Source Generator コンパイル時のメタプログラミングツール ・ 新しいC#ソースファイルを生成し,自動的に追加 ・ 開発中に実行 ・ 実行時のパフォーマンスが向上
・ リフレクションを排除 ・ AOTコンパイルとツリーシェイキングを可能に 前回の内容 https://zenn.dev/poipoionigiri/articles/57f1c33a7f5baa
どのクラス、メソッド、あるいはプロパティに対してコードを生成すべきか Syntactic Filtering: 非常に高速。テキスト情報やトークンの種類だけで判断する。 Semantic Analysis: 非常に高コスト。型解決、継承関係の確認、他アセンブリのメタデータ参照を含む。
マーカー属性 ForAttributeWithMetadataName
マーカー属性 AllInterfaces はやめましょう... ・ 推移的な依存関係 ・ アセンブリ境界の越境 ・ 増分ビルドの破壊
Blazor Form Validation - .NET 10
Marker Attribute Problem
マーカー属性の定義場所 どこにマーカー属性を定義すればよい? マーカー属性もSource Generatorでつくる?
CS0246(型または名前空間が見つかりません) × Attributeを出すだけのGeneratorを作る × 出力コードの中にAttributeの定義も混ぜ込む
Attribute用のライブラリを作る △ 2つも依存関係もつの・・・? スタンドアロンなSource Generatorがいい !
RegisterPostInitializationOutput ◎ ジェネレーターの起動時にフックして,固定のコードを差し込める. 「マーカー属性を追加してね」と言わんばかりのメソッド
CS0436 : 型の競合 複数プロジェクトにSource Generatorを入れていて, それらが依存関係にある場合に, [CS0436 : 型の競合 ]
警告が出る. → internal class
internal...
CS0436 : 型の競合(InternalsVisibleTo編) [InternalsVisibleTo]: 指定されたアセンブリに対して、通常は internal アクセスレ ベルで保護されている型やメンバーへのアクセス権を付与する宣言的な属性
CS0436 : 型の競合 (InternalsVisibleTo編) × Source Generatorに属性クラスを直接含め、DLL 自体を通常の参照としても使う ・ Source
Generatorの依存がユーザーに流れてしまう. ・ バージョンの競合が起こる可能性 ・ analyzerとして使ってほしい
CS0436 : 型の競合 (InternalsVisibleTo編) Source Generator パッケージにAttribute DLLをパックする
CS0436 : 型の競合 (InternalsVisibleTo編) .NET 10 ・ 出力するアトリビュートに[Embedded]を付与 ・ ResisterPostInitializeationOutput時に
AddEmdeddedAttributeDefinitionを呼ぶ
まとめ Source Generator の Marker Attribute Problem ・ RegisterPostInitializationOutputで Source
Generatorで生成することを考える. → Attribute は internal class ・ 複数プロジェクトで使いたい場合は,依存関係に注意 → .NET 10 では,[Embedded]を使う → それ以前では,一工夫した方が使いやすいかも