SerializationContext 類別

定義

這個類別會定義序列化作業的內容。This class defines the context of a serialization operation. 傳遞至每個參與序列化程式的內容,以提供它們可能使用的資訊,而內容會儲存從每個參與的序列化程式收集到的序列化結果。The context passed to each participating serializers to provide information that they may use, and the context stores serialization results collected from each participating serializers.

public ref class SerializationContext sealed
public sealed class SerializationContext
type SerializationContext = class
Public NotInheritable Class SerializationContext
繼承
SerializationContext

建構函式

SerializationContext(DomainXmlSerializerDirectory)

建立不含來源/目的地位置資訊的序列化內容。Create a serialization context with no source/destination location information.

SerializationContext(DomainXmlSerializerDirectory, String)

使用指定的來源/目的地位置建立序列化內容。Create a serialization context with given source/destination location.

SerializationContext(DomainXmlSerializerDirectory, String, SerializationResult)

使用指定的來源/目的地位置和 SeralizationResult 建立序列化內容。Create a serialization context with given source/destination location and SeralizationResult.

欄位

TransactionContextKey

用來識別 TransactionCoNtext 屬性包中 SerializationCoNtext 實例的唯一索引鍵Unique key used to identify SerializationContext instances in the TransactionContext property bag

屬性

Directory

序列化/還原序列化期間,序列化程式實例需要查閱其他序列化程式實例,因此此目錄提供查閱服務。A serializer instance needs to look up for other serializer instances during serialization/deserialization, so this directory provides the lookup service.

Item[String]

存取儲存在此內容中屬性的索引子。Indexer to access properties stored in this context. 屬性名稱會以區分大小寫的序數位串比較進行比較。The property name is compared by case-sensitive ordinal string comparison. 如果內容中已有屬性,設定它將會以新值覆寫舊值。If a property already exists in the context, setting it will override the old value with the new value. 如果屬性不存在於內容中,則取得它將會傳回 null,因此將屬性設為 null 將會從內容中移除它 (也就是 null 和非現有的值無法區分) 。If a property doesn't exist in the context, getting it will return null, therefore setting a property to null will remove it from the context (i.e. null and non-existing values are not distinguishable).

Location

在讀取作業中,這是來源的位置;在寫入作業中,這是目的地位置。In read operation, this is the source's location; in write operation, this is the destination location. 這通常是檔案路徑,但也可以是其他格式,取決於基礎來源/目的地。Usually this is a file path, but it can be other format as well, depending on the underlying source/destination. 如果位置無法使用,例如序列化至字串緩衝區,它也可以是 null。It can be null as well if the location is not available, e.g. serializing to a string buffer.

Result

這是從參與目前序列化作業的所有序列化程式收集而來的 SerializationResult。This is the SerializationResult collected from all serializers participating in the current serialization operation.

WriteOptionalPropertiesWithDefaultValue

是否應該在序列化期間寫出具有預設值的選擇性屬性。Whether optional properties with default value should be written out during serialization.

適用於