Format 列舉

定義

SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute 使用,以指示使用者定義型別 (UDT) 或彙總 (Aggregate) 的序列化 (Serialization) 格式。

public enum class Format
public enum Format
type Format = 
Public Enum Format
繼承
Format

欄位

Native 1

此序列化格式使用非常簡單的演算法,可讓 SQL Server 在磁碟上儲存 UDT 的有效表示。 標記為 Native 序列化的型別只能具有實值型別 (Microsoft Visual C# 中的結構 (Struct) 和 Microsoft Visual Basic .NET 中的結構 (Structure)) 做為成員。 不支援參考型別的成員 (例如,Visual C# 和 Visual Basic 中的類別),無論是使用者定義的還是 .NET 類別庫中現有的成員 (例如 String)。

Unknown 0

序列化格式不明。

UserDefined 2

此序列化格式透過 Write(BinaryWriter)Read(BinaryReader) 方法,為開發人員提供對二進位格式的完全控制。

範例

下列範例顯示 UserDefinedType Point UDT 的 屬性。 UDT 是以位元組排序,名為 「Point」、具有名為 「ValidatePoint」 的驗證方法,並使用原生串行化格式。

using Microsoft.Data.SqlClient.Server;
using System.Data.SqlTypes;
using System.Text;

[Serializable]
[Microsoft.Data.SqlClient.Server.SqlUserDefinedType(Format.Native,
     IsByteOrdered = true,
     Name = "Point", ValidationMethodName = "ValidatePoint")]
public struct Point : INullable
{

備註

這個列舉是由 SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute 用來指出使用者定義型別的串行化格式, (UDT) 或匯總。 使用 NativeUserDefined 列舉成員具有特殊需求。

  • Format.Native 格式的需求 Format.Native 如下:

    • StructLayoutAttribute如果 Value 其定義在類別中,而不是 結構,則具有的屬性值LayoutKind.Sequential必須套用至匯總或 UDT。 這會控制數據欄位的實體配置,並用來強制依其出現的順序依序配置成員。 SQL Server 使用這個屬性來判斷具有多個字段的 UDT 字段順序。

    • 類型必須包含至少一個成員, (串行化值的大小不能是零位元組) 。

    • 匯總的所有欄位都必須 是 blittable;也就是說,它們必須在Managed和Unmanaged記憶體中具有通用表示法,而且不需要Interop封送處理器的特殊處理。

    • UDT 的所有欄位都應該是下列其中一種可串行化的型別:bool、、sbyteSqlInt64SqlInt16SqlInt32SqlByteshortbyteSqlMoneySqlDoubleushortintSqlDateTimelongdoubleulonguintfloatSqlSingle,或包含這些類型之字段的使用者所定義的其他實值型別。

    • 匯總不得指定的值 MaxByteSize

    • 匯總不得有任何 [非串行化] 字段。

    • 欄位不得標示為具有) 的 明確版面設定 (StructLayoutAttribute.ValueLayoutKind.Explicit

  • Format.UserDefined 格式的需求 Format.UserDefined 如下:

適用於