Format Format Format Format Enum


SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute 用来指示用户定义类型 (UDT) 或聚合的序列化格式。Used by SqlUserDefinedTypeAttribute and SqlUserDefinedAggregateAttribute to indicate the serialization format of a user-defined type (UDT) or aggregate.

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


Native Native Native Native 1

此序列化格式使用非常简单的算法,以便于 SQL Server 能够在磁盘上存储 UDT 的高效表示形式。This serialization format uses a very simple algorithm that enables SQL Server to store an efficient representation of the UDT on disk. 标记为 Native 序列化的类型只能将值类型(在 Microsoft Visual C# 中为 struct,在 Microsoft Visual Basic .NET 中为 structure)用作成员。Types marked for Native serialization can only have value types (structs in Microsoft Visual C# and structures in Microsoft Visual Basic .NET) as members. 不支持引用类型(如 Visual C# 和 Visual Basic 中的类)的成员,无论是用户定义的成员,还是 .NET 类库中的现有成员(如 String)。Members of reference types (such as classes in Visual C# and Visual Basic), either user-defined or those existing in .NET class libraries (such as String), are not supported.

Unknown Unknown Unknown Unknown 0

该序列化格式是未知的。The serialization format is unknown.

UserDefined UserDefined UserDefined UserDefined 2

使用此序列化格式,开发人员可以通过 Write(BinaryWriter)Read(BinaryReader) 方法完全控制二进制格式。This serialization format gives the developer full control over the binary format through the Write(BinaryWriter) and Read(BinaryReader) methods.


下面的示例演示UserDefinedType点 UDT 的特性。The following example shows the UserDefinedType attribute of the Point UDT. UDT 按字节顺序排序, 命名为 "Point", 包含一个名为 "ValidatePoint" 的验证方法, 并使用本机序列化格式。The UDT is byte-ordered, is named "Point", has a validation method named "ValidatePoint", and uses the native serialization format.

     Name="Point",ValidationMethodName = "ValidatePoint")]
public struct Point : INullable
<Serializable(), SqlUserDefinedTypeAttribute(Format.Native, _
  IsByteOrdered:=True, _
  Name:="Point", _
  ValidationMethodName:="ValidatePoint")> _
  Public Structure Point
    Implements INullable


此枚举由SqlUserDefinedTypeAttributeSqlUserDefinedAggregateAttribute用于指示用户定义类型 (UDT) 或聚合的序列化格式。This enumeration is used by SqlUserDefinedTypeAttribute and SqlUserDefinedAggregateAttribute to indicate the serialization format of a user-defined type (UDT) or aggregate. NativeUserDefined枚举成员的使用具有特殊要求。Use of the Native and UserDefined enumeration members has special requirements.

  • Format.Native

    Format.Native格式的要求如下:The requirements for the Format.Native format are:

    • 如果属性值LayoutKind.Sequential为, 则必须将其应用到聚合或 UDT (如果它是在类中定义的, 而不是在结构中定义的)。 Value StructLayoutAttributeThe StructLayoutAttribute with a Value property value of LayoutKind.Sequential must be applied to the aggregate or UDT if it is defined in a class and not a structure. 这会控制数据字段的物理布局, 并用于强制成员按其出现的顺序进行排列。This controls the physical layout of the data fields and is used to force the members to be laid out sequentially in the order they appear. SQL Server 使用此属性确定具有多个字段的 Udt 的字段顺序。SQL Server uses this attribute to determine the field order for UDTs with multiple fields.

    • 该类型必须包含至少一个成员 (序列化值的大小不能为零个字节)。The type must contain at least one member (serialized values cannot be zero bytes in size).

    • 聚合的所有字段必须是可复制的;也就是说, 它们必须在托管内存和非托管内存中都有共同的表示形式, 并且不需要互操作封送拆收器进行特殊处理。All the fields of the aggregate must be blittable; that is, they must have a common representation in both managed and unmanaged memory and not require special handling by the interop marshaler.

    • boolUDT 的所有字段应为以下类型之一:、 ushort int byte longsbyteshort、、 uint 、、、floatulong``double 、、SqlMoney、 、SqlDateTime、 、SqlInt64、、、或由用户定义的值类型, 其中包含其中一项的字段SqlSingle SqlInt32 SqlByte SqlInt16 SqlDouble各种.All the fields of the UDT should be of one of the following types that can be serialized: bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, SqlByte, SqlInt16, SqlInt32, SqlInt64, SqlDateTime, SqlSingle, SqlDouble, SqlMoney, or other value types defined by the user that contain fields of one of these types.

    • 聚合不得为MaxByteSize指定值。The aggregate must not specify a value for MaxByteSize.

    • 聚合不能包含任何 [非系列化] 字段。The aggregate must not have any [NonSerialized] fields.

    • 字段不能标记为显式布局 (具有StructLayoutAttribute.ValueLayoutKind.Explicit)。Fields must not be marked as an explicit layout (with a StructLayoutAttribute.Value of LayoutKind.Explicit).

  • Format.UserDefined

    Format.UserDefined格式的要求如下:The requirements for the Format.UserDefined format are: