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
February 28, 2026
Programming
310
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
GitHub Agentic Workflows を触ってみる
htkym
2
960
すこし踏み込む CancellationToken
htkym
2
1.7k
AIの中の人になってみる
htkym
0
220
今さら聞けない .NET CLI
htkym
0
270
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
170
今さら聞けないCancellationToken
htkym
0
330
GitHub Copilot CLIのいいところ
htkym
2
1.5k
GitHubCopilotCLIをはじめよう.pdf
htkym
0
430
RoslynAnalyzerをつかってみよう
htkym
0
1.3k
Other Decks in Programming
See All in Programming
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
1
430
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
350
JRuby: Past, Present, and Future
headius
0
230
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
160
mrbgem 三角測量 開発
ogom
0
230
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
690
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
570
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
160
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
APNsからLive Activityを開始する話
yumnumm
0
160
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
16k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
Featured
See All Featured
Building Adaptive Systems
keathley
44
3.2k
Google's AI Overviews - The New Search
badams
0
1.6k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
780
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
450
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Deep Space Network (abreviated)
tonyrice
0
360
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
440
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Optimising Largest Contentful Paint
csswizardry
37
4k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
270
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]を使う → それ以前では,一工夫した方が使いやすいかも