SalBinary
Namespace: PPJ.Runtime
Assembly: PPJ.Web.50 (5.0.0.0)
Wraps a byte array as a SAL binary value.
- C#
- VB.NET
public class SalBinary : ISalType
Public Class SalBinary
Inherits ISalType
The supplied array is retained without copying. Both null and zero-length arrays represent SAL null. Access through ISalType reports DbType.Binary and returns DBNull.Value for a null value.
Example:
using PPJ.Runtime;
byte[] bytes = { 1, 2, 3 };
SalBinary value = new SalBinary(bytes);
SalNumber length = value.Length; // 3
value.Value[0] = 9; // Also changes bytes[0].
SalBinary prefix = SalBinary.Empty;
value.SetBufferLength(ref prefix, 2); // Copies { 9, 2 }.
Constructors
SalBinary()
Initializes a SAL binary value with a null buffer.
SalBinary(buffer)
Initializes a binary value using the supplied buffer.
| Name | Type | Description |
|---|---|---|
| buffer | Byte[] | The byte array to retain, or null. The array is not copied. |
Fields
| Name | Type | Description | Value |
|---|---|---|---|
| Empty | SalBinary | Represents the shared empty binary value. |
Properties
IsNull
Boolean: Gets whether the buffer is null or empty.
Length
SalNumber: Gets the number of bytes in the buffer.
Value
Byte[]: Gets the underlying byte array.
The returned array is the stored array, not a copy. Modifying its elements changes this value.
Methods
GetBufferLength()
Returns the number of bytes in the buffer.
Returns: SalNumber. The buffer length, or zero for a null or empty value.
SetBufferLength(target, length)
Copies a prefix of this buffer into a new binary value.
| Parameter | Type | Description |
|---|---|---|
| target | SalBinary | Receives the copied prefix, or Empty when the requested length is zero or negative. |
| length | Int32 | The number of bytes to copy. A positive value must not exceed the source buffer length. |
Returns: Boolean. True after the target has been assigned.
This method does not pad or grow the source buffer. Throws:
- ArgumentNullException The requested length is positive and the source buffer is null.
- ArgumentException The requested length exceeds the source buffer length.
Example:
using PPJ.Runtime;
SalBinary source = new SalBinary(new byte[] { 10, 20, 30, 40 });
SalBinary prefix = SalBinary.Empty;
source.SetBufferLength(ref prefix, 2);
// prefix.Value contains { 10, 20 }; source.Value still contains all four bytes.
source.SetBufferLength(ref prefix, 0); // Assigns SalBinary.Empty.
// A positive length greater than source.Value.Length is invalid.
Implements
| Name | Description |
|---|---|
| ISalType | Exposes a SAL value in the form used for database parameter binding. |