Skip to content

Update reflection.md#30

Open
TheMathGeek314 wants to merge 3 commits intoPrashantMohta:mainfrom
TheMathGeek314:patch-2
Open

Update reflection.md#30
TheMathGeek314 wants to merge 3 commits intoPrashantMohta:mainfrom
TheMathGeek314:patch-2

Conversation

@TheMathGeek314
Copy link
Copy Markdown
Contributor

I don't know about private properties or the ReflectionHelper, so this isn't a complete guide, but hopefully it's still helpful

I don't know about private properties or the ReflectionHelper, so this isn't a complete guide, but hopefully it's still helpful
Copy link
Copy Markdown
Contributor

@BadMagic100 BadMagic100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread reflection.md
Comment thread reflection.md

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>);`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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#

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I may be familiar with C#, properties are not something I've used much and hence cannot describe or provide examples

Comment thread reflection.md Outdated
Moved TODO to the bottom, made example FieldInfo static
Initialize FieldInfo at declaration instead of within a method
Comment thread reflection.md

### TODO
- Explain Instance, Static, public, non public
- Explain reflection (please use HC/GM to explain instead of random placeholder names)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To this point is there a reason you used GameCameras as the example instead of one of these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants