Update reflection.md#30
Conversation
I don't know about private properties or the ReflectionHelper, so this isn't a complete guide, but hopefully it's still helpful
BadMagic100
left a comment
There was a problem hiding this comment.
Please remove the todo-list items you've completed (e.g. "Explain reflection"). I'd also consider other low-hanging fruit like explaining the difference between instance/static and public/nonpublic but would not block over it
|
|
||
| If you need to read, write, or invoke private fields and methods, this is possible to do with reflection. Usually they are private for a reason, so be sure you know what you're doing. | ||
|
|
||
| To access a nonpublic field, you can define a `FieldInfo` object to reference a class's field by name. This is an expensive process, so it is good practice to define the field once and only access its value at runtime. To do this, call `typeof(<the class you want>).GetField(<the field name>, <the corresponding BindingFlags>);` |
There was a problem hiding this comment.
fwiw, properties largely act the same as fields from a reflection standpoint but you use GetProperty/PropertyInfo instead. Though I'd imagine we should cover the difference between a field and a property for people not as familiar with c#
There was a problem hiding this comment.
As much as I may be familiar with C#, properties are not something I've used much and hence cannot describe or provide examples
Moved TODO to the bottom, made example FieldInfo static
Initialize FieldInfo at declaration instead of within a method
|
|
||
| ### TODO | ||
| - Explain Instance, Static, public, non public | ||
| - Explain reflection (please use HC/GM to explain instead of random placeholder names) |
There was a problem hiding this comment.
To this point is there a reason you used GameCameras as the example instead of one of these
I don't know about private properties or the ReflectionHelper, so this isn't a complete guide, but hopefully it's still helpful