Format 枚举

定义

SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute 用来指示用户定义类型 (UDT) 或聚合的序列化格式。

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) 或聚合。 Native使用 和 UserDefined 枚举成员有特殊要求。

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

    • StructLayoutAttribute属性值为 ValueLayoutKind.Sequential 必须应用于聚合或 UDT(如果在类而不是结构中定义)。 这会控制数据字段的物理布局,并用于强制成员按其出现顺序进行布局。 SQL Server使用此属性来确定具有多个字段的 UDT 的字段顺序。

    • 类型必须至少包含一个成员, (序列化值的大小) 不能为零字节。

    • 聚合的所有字段都必须是 blittable;也就是说,它们必须在托管和非托管内存中具有通用的表示形式,并且不需要互操作封送处理器进行特殊处理。

    • UDT 的所有字段应为可序列化的下列类型之一:bool、、bytesbyteshortSqlSingleulongfloatlongdoubleuintSqlByteSqlInt16intushortSqlInt64SqlDateTimeSqlInt32SqlDoubleSqlMoney、或用户定义的其他值类型,这些值类型包含其中一种类型的字段。

    • 聚合不能为 MaxByteSize指定值。

    • 聚合不得有任何 [NonSerialized] 字段。

    • 字段不得标记为具有) 的显式布局 (StructLayoutAttribute.ValueLayoutKind.Explicit

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

适用于