Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new GetValue method to System.Reflection #7040

Closed
Esidar opened this issue Nov 23, 2016 · 1 comment
Closed

Add new GetValue method to System.Reflection #7040

Esidar opened this issue Nov 23, 2016 · 1 comment

Comments

@Esidar
Copy link

Esidar commented Nov 23, 2016

This new method would accept an "object" to which a Value could be copied instead of being unnecessarily boxed. Example of use would look like this:

static object boxedFloat = null;
....
boxedFloat = fieldInfo.GetValue( myObject, boxedFloat );

Boxing of the value would occur only once. This would eliminate unnecessarily memory allocations in situations when GetValue is called many times. When method is used on a class types, copying would not occur and stored object would be returned instead.

One of the uses of GetValue method is User Interface based on MVVM (Model View Viewmodel) where values used to control an UI are pulled directly from the data. In realtime applications (like games) this boxing makes hundreds if not thousands of unnecessary memory allocations every second.

@Esidar Esidar closed this as completed Nov 23, 2016
@Esidar Esidar reopened this Nov 23, 2016
@MichalStrehovsky
Copy link
Member

A box-free way to do GetValue/SetValue would be an interesting addition to FieldInfo, but I wonder if adding T GetValue<T>(object) with a corresponding void SetValue<T>(object, T) wouldn't be a cleaner API surface to achieve that.

That said, this issue is unlikely to get traction in the CoreCLR repo - API addition proposals should follow the API review process and get filed in the CoreFX repo - that's where the community discusses API additions to .NET.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftbot msftbot bot locked as resolved and limited conversation to collaborators Dec 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants