ScriptIgnoreAttribute 类

定义

指定 JavaScriptSerializer 不序列化公共属性或公共字段。 此类不能被继承。

public ref class ScriptIgnoreAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
public sealed class ScriptIgnoreAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
public sealed class ScriptIgnoreAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)>]
type ScriptIgnoreAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)>]
type ScriptIgnoreAttribute = class
    inherit Attribute
Public NotInheritable Class ScriptIgnoreAttribute
Inherits Attribute
继承
ScriptIgnoreAttribute
属性

示例

The following example demonstrates how to apply ScriptIgnoreAttribute to the Comment field in the custom class named Group. 这指示 JavaScriptSerializer 将类的实例序列化为 JSON 格式时忽略字段。

using System;
using System.Web.Script.Serialization;

public class Group
{
    // The JavaScriptSerializer ignores this field.
    [ScriptIgnore]
    public string Comment;

    // The JavaScriptSerializer serializes this field.
    public string GroupName;
}
Imports System.Web.Script.Serialization

Public Class Group
    ' The JavaScriptSerializer ignores this field.
    <ScriptIgnore()> Public Comment As String

    ' The JavaScriptSerializer serializes this field.
    Public GroupName As String
End Class

注解

如果将类的实例序列化为 JavaScript 对象表示法 (JSON) 格式,则应用于 ScriptIgnoreAttribute 类的公共属性或公共字段,则 JavaScriptSerializer 忽略或跳过该成员。

如果属性ResponseFormat设置为 Xml.,则ScriptIgnoreAttribute此属性将不起作用。 如果要在序列化为 XML 格式时具有相同的行为, XmlIgnoreAttribute 应改为应用于属性或字段。 这是因为类将通过使用 XmlSerializer 而不是 JavaScriptSerializer序列化。

还可以同时 ScriptIgnoreAttribute 应用和 XmlIgnoreAttribute 属性或字段。 在这种情况下,将忽略 JSON 和 XML 响应格式的属性或字段。

有关如何使用属性的详细信息,请参阅 “属性”。

构造函数

ScriptIgnoreAttribute()

初始化 ScriptIgnoreAttribute 类的新实例。

属性

ApplyToOverrides

获取或设置是否重写 ScriptIgnoreAttribute,以便 JavaScriptSerializer 将考虑公共属性或公共字段的序列化。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于