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
C#のリフレクションを使ってみよう
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
kyoma
April 26, 2019
Programming
3.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
C#のリフレクションを使ってみよう
C#におけるリフレクションの概略
・概要
・できること
・使用上の注意
kyoma
April 26, 2019
Transcript
26 slides
C#のリフレクションを使っ てみよう きょーま
name : きょーま job : クライアントエンジニア ・新機能開発 ・デバッグ機能 ・Unity /
C# / C++ hobby : ゲーム、お絵かき、酒 自己紹介 profile
みなさん
C# 使ってますか?
リフレクション 使ってますか?
#リフレクションとは • C#の機能の一つ • 実行時型情報と呼ばれるもの • プログラム実行時に メタデータを取り出す機能 • “C#
リフレクション” で検索検索ゥ what is reflection ?
要するに
文字列から指定クラスの インスタンスを作ったり
privateなメンバを参照したり
privateなメソッドを 外から実行できる
非常に治安の悪い機能!!
チュートリアル tutorial 1. インスタンスを作る 2. privateなフィールドを取得 3. privateなメソッドを呼ぶ
基本的な使い方 how to use 1. SystemとSystem.Reflection をusing 2. Typeを取得 3.
Typeから FieldInfo、MethodInfoを取得
例えば こんなクラスがあったとする
← インスタンスを作る ← privateなフィールドを取得 ← privateなメソッドを呼ぶ
検索方法の制御 BindingFlags BindingFlags • フィールドやメソッドを 取得するときの条件 • NonPublicでprivateを対象に • 他にもstaticをとったり
大文字小文字を無視したり • 詳しくはWebで!!
これでpublicとかprivateとか 気にせずコードを書けるぜ あいつのコード、 privateばっかでうぜーんだよな
ダメです
リフレクションを使用す るべきではない理由 why not use reflection • カプセル化を破壊する • パフォーマンスが悪い
基本的にロジックや設計に リフレクションを使うべきでない
リフレクションの活 用場所 effective use of reflection • デバッグ機能 • ホットリロードなツール
デバッグ機能 for debugging • デバッグのために ロジックが歪にならない • メインロジックの 単体テストが容易にできる
ホットリロード なツール for hot reload • ゲームを動かしながらできる データ反映やデバッグ機能 • 試行錯誤が容易
ホットリロードな デバッグツールの例 example hot reload debugging tool • フィールドのある地点に 障害物や敵キャラを配置する
• 戦闘中にあるキャラクターの パラメータを変更する
ゲームロジック のクラス群 デバッグ機能 or データツール ロジックとデバッグ用のコードを切り離せる ゲームロジック内にテストコードを 書かなくて良いという意味ではない リフレクションで参照 高い凝集度・疎結合
1つのプロジェクト
まとめ summary • C#にはリフレクションって 治安が悪い機能があるよ • メインロジックでは 基本的に使わないのが吉だよ • 工夫すれば、
便利な使い方ができるよ
Other Decks in Programming
See All in Programming
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
560
LLM 101
dalinaum
0
480
Next.js: The final boss of Web Performance
guaca
0
400
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
330
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
190
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
300
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.5k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
430
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
170
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
530
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Exploring anti-patterns in Rails
aemeredith
4
560
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
エンジニアに許された特別な時間の終わり
watany
109
250k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
880
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
450
Docker and Python
trallard
47
4.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k