c# - FieldInfo.GetRawConstantValue 在 UWP 上不可用
问题描述
我需要在我的类中获取一个常量的值。
GetField
工作正常。
但是myFieldInfo.GetRawConstantValue()
通常可以完美运行,但在 UWP 上不可用。
有没有办法在 UWP 上实现这一点?
解决方案
有没有办法在 UWP 上实现这一点?
源自本文档。GetRawConstantValue
方法适用于.NET Standard
。因此,您可以创建.NET Standard
可以被 UWP 项目引用的类库。
public class LibCore
{
public static object GetRawConstantValue(Type target, string filedName)
{
var filed = target.GetField(filedName);
var value = filed.GetRawConstantValue();
return value;
}
}
用法
var value = LibCore.GetRawConstantValue(typeof(Person), "Name");
注意:如果.NET Standard
类库版本为2.0,则需要修改uwp min version为16299。
推荐阅读
- kubernetes - Sumo Logic kubernetes 集成要求不存在 Prometheus
- hyperledger-fabric - 从 Fabric 链码中验证 Indy 凭证
- python - 使用 subplot 和 FuncAnimation 生成多行
- angular - 如何调用路由器导航方法而不是routerLink?
- sql - 如何授予 Oracle 中所有包和过程的仅查看权限?
- php - MySQL 查询找到行但不返回任何内容
- r - 如何在 R 中忽略循环中的缺失值和 NA?
- python-3.x - 根据 groupby 中的比例填充分类 NaN 值
- android - Android camera2 YUV 2048x1536 捕获的图像被拉伸(不是预览)
- docker - 如何为 htslib 使用 Snakemake 容器(bgzip + tabix)