FieldInfo.GetRawConstantValue is not avaliable on UWP

159 Views Asked by At

I need to get a value of a constant inside my class. GetField works fine.

But then myFieldInfo.GetRawConstantValue() normally works perfectly, but is not available on UWP.

Is there any way to achieve this on UWP?

1

There are 1 best solutions below

0
On

Is there any way to achieve this on UWP?

Derive from this document. GetRawConstantValue method apply to .NET Standard. So you could create .NET Standard class library that could referenced by UWP project.

public class LibCore
{
    public static object GetRawConstantValue(Type target, string filedName)
    {
        var filed = target.GetField(filedName);
        var value = filed.GetRawConstantValue();
        return value;
    }
}

Usage

var value = LibCore.GetRawConstantValue(typeof(Person), "Name");

Note: If version of .NET Standard class library is 2.0, you need modify uwp min version to 16299.