FormatterServices.GetSafeUninitializedObject(Type) 方法
定义
创建指定对象类型的新实例。Creates a new instance of the specified object type.
public:
static System::Object ^ GetSafeUninitializedObject(Type ^ type);
public static object GetSafeUninitializedObject (Type type);
[System.Security.SecurityCritical]
public static object GetSafeUninitializedObject (Type type);
static member GetSafeUninitializedObject : Type -> obj
[<System.Security.SecurityCritical>]
static member GetSafeUninitializedObject : Type -> obj
Public Shared Function GetSafeUninitializedObject (type As Type) As Object
参数
- type
- Type
要创建的对象的类型。The type of object to create.
返回
指定类型的归零对象。A zeroed object of the specified type.
- 属性
例外
type 参数为 null。The type parameter is null.
type 参数不是有效的公共语言运行时类型。The type parameter is not a valid common language runtime type.
调用方没有所要求的权限。The caller does not have the required permission.
注解
由于对象的新实例初始化为零,且没有运行任何构造函数,因此该对象可能不表示该对象认为有效的状态。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. GetSafeUninitializedObject 仅当用户打算立即填充所有字段时,才应使用进行反序列化。GetSafeUninitializedObject 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.
GetSafeUninitializedObject 将所有类级别 链接要求 转换为 请求 ,以确保所有直接和间接调用方都具有该要求指定的权限。GetSafeUninitializedObject converts all class level Link Demands to Demands to ensure that all direct and indirect callers have the permissions that the demand specifies. 用于在 GetSafeUninitializedObject 从部分受信任的源反序列化时提高安全级别。Use GetSafeUninitializedObject to increase the level of security when deserializing from a partially trusted source. 若要在完全信任的情况下提高性能,请使用 GetUninitializedObject 。For better performance in full trust scenarios, use GetUninitializedObject.