获取使用反射属性参考

编程入门 行业动态 更新时间:2024-10-25 20:26:57
本文介绍了获取使用反射属性参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 var a = new obj(); var property = a.GetType().GetProperty("DB").GetValue(a,null) as testObject;

这是否意味着变量属性举行与我在对象中得到了相同的对象,或者一个新的TestObject参考有人认为,持有相同的价值观?

does this mean that the variable property hold a reference to the the same object that i got in object a , or a new testObject was made that holds the same values?

如果这意味着创建一个新的对象,然后我怎么可以得到参考该物业/支持字段使用反射?

if this means creating a new object, then how can i get the reference to that property/backing field using reflection?

推荐答案

属性现在持有的 referece 应用于无论是在 A 的 DB 属性。

property now holds a referece to whatever is in a's DB property.

我不知道但是当你调用会发生什么的GetValue()对具有值类型的属性,我想你会得到原始值的装箱副本的引用,如装箱和拆箱(C#编程指南):

I'm not sure though what happens when you call GetValue() on a property that has a value type, I suppose you get a reference to a boxed copy of the original value, as explained in Boxing and Unboxing (C# Programming Guide):

拳击值类型[为对象在的GetValue()的情况下]分配的堆和值拷贝到新对象的对象实例。

Boxing a value type [to object in GetValue()'s case] allocates an object instance on the heap and copies the value into the new object.

更多推荐

获取使用反射属性参考

本文发布于:2023-11-12 11:41:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:反射   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!