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
0
230
SourceGeneratorのマーカー属性問題について
tkym
February 28, 2026
Tweet
Share
More Decks by tkym
See All by tkym
RoslynAnalyzerをつかってみよう
htkym
0
440
SourceGeneratorのススメ
htkym
0
820
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
190
.NET 10のEntity Framework Coreの新機能
htkym
0
990
.NET 10のBlazorの期待の新機能
htkym
0
1.2k
Azure Static Web Appsでユニバーサルリンク
htkym
0
43
Aspireとazdでデプロイが簡単に
htkym
0
36
Azure Blob Storageでユニバーサルリンク
htkym
0
220
Other Decks in Programming
See All in Programming
Coding as Prompting Since 2025
ragingwind
0
490
20260320登壇資料
pharct
0
140
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
220
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
720
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
200
AI活用のコスパを最大化する方法
ochtum
0
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
1.2k
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
1.4k
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
Tamach-sre-3_ANDPAD-shimaison93
mane12yurks38
0
200
20260315 AWSなんもわからん🥲
chiilog
2
180
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
830
Build your cross-platform service in a week with App Engine
jlugia
234
18k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
220
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
230
The Limits of Empathy - UXLibs8
cassininazir
1
280
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
320
Done Done
chrislema
186
16k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
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]を使う → それ以前では,一工夫した方が使いやすいかも