ValidationContext 构造函数

定义

初始化 ValidationContext 类的新实例。

重载

名称 说明
ValidationContext(Object)

使用指定的对象实例初始化类的新实例 ValidationContext

ValidationContext(Object, IDictionary<Object,Object>)

使用指定的对象和可选的属性包初始化类的新实例 ValidationContext

ValidationContext(Object, IServiceProvider, IDictionary<Object,Object>)

使用服务使用者的服务提供程序和字典初始化类的新实例 ValidationContext

ValidationContext(Object, String, IServiceProvider, IDictionary<Object,Object>)

为具有可选属性包的给定对象实例构造一ValidationContextdisplayName个可选serviceProvider属性包items

ValidationContext(Object)

Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs

使用指定的对象实例初始化类的新实例 ValidationContext

public:
 ValidationContext(System::Object ^ instance);
public ValidationContext(object instance);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")]
public ValidationContext(object instance);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
public ValidationContext(object instance);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance);
new System.ComponentModel.DataAnnotations.ValidationContext : obj -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj -> System.ComponentModel.DataAnnotations.ValidationContext
Public Sub New (instance As Object)

参数

instance
Object

要验证的对象实例。 它不能 null

属性

例外

instancenull

适用于

ValidationContext(Object, IDictionary<Object,Object>)

Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs

使用指定的对象和可选的属性包初始化类的新实例 ValidationContext

public:
 ValidationContext(System::Object ^ instance, System::Collections::Generic::IDictionary<System::Object ^, System::Object ^> ^ items);
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object,object> items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")]
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object,object?>? items);
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object,object?>? items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object,object?>? items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance, System.Collections.Generic.IDictionary<object,object?>? items);
new System.ComponentModel.DataAnnotations.ValidationContext : obj * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
Public Sub New (instance As Object, items As IDictionary(Of Object, Object))

参数

instance
Object

要验证的对象实例。 它不能 null

items
IDictionary<Object,Object>

一组可选的键/值对,供使用者使用。

属性

例外

instancenull

注解

items如果是null,则会创建一个空字典。 如果 items 不是 null,则将键/值对集复制到新字典中,从而阻止使用者修改原始字典。

适用于

ValidationContext(Object, IServiceProvider, IDictionary<Object,Object>)

Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs
Source:
ValidationContext.cs

使用服务使用者的服务提供程序和字典初始化类的新实例 ValidationContext

public:
 ValidationContext(System::Object ^ instance, IServiceProvider ^ serviceProvider, System::Collections::Generic::IDictionary<System::Object ^, System::Object ^> ^ items);
public ValidationContext(object instance, IServiceProvider serviceProvider, System.Collections.Generic.IDictionary<object,object> items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")]
public ValidationContext(object instance, IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object,object?>? items);
public ValidationContext(object instance, IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object,object?>? items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")]
public ValidationContext(object instance, IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object,object?>? items);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")]
public ValidationContext(object instance, IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object,object?>? items);
new System.ComponentModel.DataAnnotations.ValidationContext : obj * IServiceProvider * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Constructing a ValidationContext without a display name is not trim-safe because it uses reflection to discover the type of the instance being validated in order to resolve the DisplayNameAttribute when a display name is not provided.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * IServiceProvider * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * IServiceProvider * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered and the Type's properties can be trimmed.")>]
new System.ComponentModel.DataAnnotations.ValidationContext : obj * IServiceProvider * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
Public Sub New (instance As Object, serviceProvider As IServiceProvider, items As IDictionary(Of Object, Object))

参数

instance
Object

要验证的对象。 此参数是必需的。

serviceProvider
IServiceProvider

实现 IServiceProvider 接口的对象。 此参数是可选的。

items
IDictionary<Object,Object>

要提供给服务使用者的键/值对字典。 此参数是可选的。

属性

例外

instancenull

注解

serviceProvider 参数表示方法可用于 GetService 执行自定义验证的服务。

如果参数 itemsnull,则会创建一个空字典。 如果参数不是 null,则键/值对集将复制到新的字典中,从而阻止服务使用者修改原始字典。

适用于

ValidationContext(Object, String, IServiceProvider, IDictionary<Object,Object>)

Source:
ValidationContext.cs
Source:
ValidationContext.cs

为具有可选属性包的给定对象实例构造一ValidationContextdisplayName个可选serviceProvider属性包items

public:
 ValidationContext(System::Object ^ instance, System::String ^ displayName, IServiceProvider ^ serviceProvider, System::Collections::Generic::IDictionary<System::Object ^, System::Object ^> ^ items);
public ValidationContext(object instance, string displayName, IServiceProvider? serviceProvider, System.Collections.Generic.IDictionary<object,object?>? items);
new System.ComponentModel.DataAnnotations.ValidationContext : obj * string * IServiceProvider * System.Collections.Generic.IDictionary<obj, obj> -> System.ComponentModel.DataAnnotations.ValidationContext
Public Sub New (instance As Object, displayName As String, serviceProvider As IServiceProvider, items As IDictionary(Of Object, Object))

参数

instance
Object

正在验证的对象实例。 它不能 null

displayName
String

与对象实例关联的显示名称。

serviceProvider
IServiceProvider

在调用时GetService(Type)使用可选IServiceProvider

null如果是,GetService(Type)将始终返回null

items
IDictionary<Object,Object>

可选的键/值对集,供使用者通过 Items

如果 null为空字典,则会创建一个空字典。 null否则,键/值对集将复制到新字典中,防止使用者修改原始字典。

例外

何时 instancenull

注解

此构造函数是剪裁安全的,因为它不使用反射来解析 instance 类型以支持设置 DisplayName。

适用于