如何从 C# 中的未知枚举中获取值?
我实际上正在编写一个扩展对象的 deepToString-Method 。这使用反射来获取对象的每个属性并调用该属性的 deepToString-Method。除了枚举之外,一切都工作正常。如果我尝试将 PropertyInfo.GetValue()
与枚举一起使用,它总是返回零。
我怎样才能得到真正的int值?我缺少什么?
I'm actually programming a deepToString-Method that extends object. This uses reflection to get each property of an object and calls the deepToString-Method for this property. Everything works fine except of Enums. If I try to use PropertyInfo.GetValue()
with an enum, it allways returns zero.
How can I get the real int-Value? What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我必须补充一点,反思是邪恶的。真正需要它的场合很少见。
I have to add that reflection is EVIL. Rare are the occasions where it is really needed..