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
0
110
SourceGeneratorのマーカー属性問題について
tkym
February 28, 2026
Tweet
Share
More Decks by tkym
See All by tkym
SourceGeneratorのススメ
htkym
0
740
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
180
.NET 10のEntity Framework Coreの新機能
htkym
0
970
.NET 10のBlazorの期待の新機能
htkym
0
1.2k
Azure Static Web Appsでユニバーサルリンク
htkym
0
37
Aspireとazdでデプロイが簡単に
htkym
0
34
Azure Blob Storageでユニバーサルリンク
htkym
0
210
Other Decks in Programming
See All in Programming
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
株式会社 Sun terras カンパニーデック
sunterras
0
1.9k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
380
TROCCOで実現するkintone+BigQueryによるオペレーション改善
ssxota
0
120
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
120
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
130
Ruby x Terminal
a_matsuda
5
550
浮動小数の比較について
kishikawakatsumi
0
360
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
180
AI活用のコスパを最大化する方法
ochtum
0
120
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
130
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
480
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
89
Technical Leadership for Architectural Decision Making
baasie
3
270
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Everyday Curiosity
cassininazir
0
150
Utilizing Notion as your number one productivity tool
mfonobong
4
240
How GitHub (no longer) Works
holman
316
140k
Believing is Seeing
oripsolob
1
68
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
360
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
110
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
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]を使う → それ以前では,一工夫した方が使いやすいかも