buunguyen / fasterflect

.NET Reflection Made Fast and Simple ⛺
https://www.nuget.org/packages/fasterflect/
Apache License 2.0
285 stars 57 forks source link

ValueTypeHolder's Value property is internal only #5

Open hybridherbst opened 6 years ago

hybridherbst commented 6 years ago

Why is it not possible to set the Value contained in a wrapper? For structs, it works fine using the Get/Set methods, but for base value types (such as float, int, ...) this doesn't work, as they don't have a "setter" method or something.

Or am I missing something?

ffhighwind commented 4 years ago

It works, but you have to know the correct field/property. For most basic types this is "m_value", at least on .NET 4.5

FieldInfo field = typeof(int).GetField("m_value", BindingFlags.Public | BindingFlags.Instance);
int a = 5;
int result = (int) field.GetValue(a);