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
tkym
February 28, 2026
Programming
240
0
Share
SourceGeneratorのマーカー属性問題について
tkym
February 28, 2026
More Decks by tkym
See All by tkym
GitHubCopilotCLIをはじめよう.pdf
htkym
0
140
RoslynAnalyzerをつかってみよう
htkym
0
670
SourceGeneratorのススメ
htkym
0
850
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
190
.NET 10のEntity Framework Coreの新機能
htkym
0
1k
.NET 10のBlazorの期待の新機能
htkym
0
1.3k
Azure Static Web Appsでユニバーサルリンク
htkym
0
46
Aspireとazdでデプロイが簡単に
htkym
0
39
Azure Blob Storageでユニバーサルリンク
htkym
0
220
Other Decks in Programming
See All in Programming
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
270
Coding as Prompting Since 2025
ragingwind
0
830
Swift Concurrency Type System
inamiy
0
530
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
330
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
190
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
220
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
3
330
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
490
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
4.9k
おれのAgentic Coding 2026/03
tsukasagr
1
150
Make GenAI Production-Ready with Kubernetes Patterns
bibryam
0
120
AI-DLC Deep Dive
yuukiyo
8
3.9k
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
220
Building a Scalable Design System with Sketch
lauravandoore
463
34k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.5k
The Limits of Empathy - UXLibs8
cassininazir
1
300
Exploring anti-patterns in Rails
aemeredith
3
320
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Technical Leadership for Architectural Decision Making
baasie
3
330
Chasing Engaging Ingredients in Design
codingconduct
0
170
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
330
Balancing Empowerment & Direction
lara
6
1.1k
Prompt Engineering for Job Search
mfonobong
0
270
エンジニアに許された特別な時間の終わり
watany
106
240k
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]を使う → それ以前では,一工夫した方が使いやすいかも