- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通常我会调用 Expression.New(type)
,但是当类型没有无参数构造函数时,这是不可能的。
FormatterServices.GetUninitializedObject()
在内部如何工作?operator new()
是否比调用 FormatterServices.GetUninitializeObject()
更快?GetUninitializedObject
等效的 Expressions
,或者唯一的方法是使用 Expression.Call
?最佳答案
来自 MSDN :
Because the new instance of the object is initialized to zero and no constructors are run, the object might not represent a state that is regarded as valid by that object. The current method should only be used for deserialization when the user intends to immediately populate all fields. It does not create an uninitialized string, since creating an empty instance of an immutable type serves no purpose.
所以,回答你的问题:
new()
构造函数什么都不做,它们可能大致相同。Expression.Call
,它会返回一个 object
然后如果你想用它做任何事情 Expression.Convert
到任何类型你需要这个对象。关于c# - 是否有等同于 FormatterServices.GetUninitializedObject() 的表达式树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470229/
我对一些序列化的东西很好奇,所以我四处寻找 FormatterServices 并找到了一个名为 nativeGetUninitializedObject 的方法,它实际上处理给定的初始化(不调用 c
我的问题相对简单,我感觉 GetUninitializedObject(type) 方法不会在不调用任何构造函数的情况下生成给定类型的新实例,而是生成一个新的对象,它的行为与正确的对象相同(具有相同的
通常我会调用 Expression.New(type),但是当类型没有无参数构造函数时,这是不可能的。 FormatterServices.GetUninitializedObject() 在内部如何
是否有其他方法可以在 UWP (NETCore) 中创建“未初始化”对象?我正在尝试移植一段使用 对象 o = FormatterServices.GetUninitializedObject(类型)
我是一名优秀的程序员,十分优秀!