SalVariant
Namespace: PPJ.Runtime.Com
Assembly: PPJ.Web.50 (5.0.0.0)
Stores an automation value and exposes SAL and CLR conversion operations.
- C#
- VB.NET
public class SalVariant : SalFunctionalClass
Public Class SalVariant
Inherits SalFunctionalClass
Assigning Value updates the associated SAL and automation type codes. The Get methods report unsupported categories through their Boolean result; direct To methods use System.Convert and can throw conversion exceptions.
Example:
using PPJ.Runtime;
using PPJ.Runtime.Com;
var variant = new SalVariant(42);
SalNumber number = 0;
if (variant.GetNumber(ref number))
System.Console.WriteLine(number.ToInt32());
Constructors
SalVariant()
Initializes an empty variant.
SalVariant(value)
Initializes a variant with the supplied value.
| Name | Type | Description |
|---|---|---|
| value | Object | The value to store. |
Properties
Optional
SalVariant: Gets a new variant containing Type.Missing for an omitted optional automation argument.
Value
Object: Gets or sets the stored value and updates its SAL and automation type codes.
Methods
ActiveXType()
Gets the automation category of the stored value.
Returns: SalNumber. The COM VarEnum value.
AsActiveX(vt)
Converts and replaces the stored value using a supported automation scalar type.
| Parameter | Type | Description |
|---|---|---|
| vt | SalNumber | The target COM VarEnum type code. |
Returns: SalBoolean. True after conversion; false if the type is unsupported.
Supports strings, dates, numeric types, decimals, and currency; unsupported type codes return false. Conversion failures can throw.
GetBlob(s)
Reads an array variant as binary SAL string data.
| Parameter | Type | Description |
|---|---|---|
| s | SalString | Receives the converted value when the category is supported. |
Returns: SalBoolean. True for an array or empty variant; otherwise, false.
A byte array supplies the binary data. Other arrays and empty variants produce SalString.Null.
GetBoolean(b)
Converts a Boolean, numeric, string, date, or empty variant to a SAL Boolean.
| Parameter | Type | Description |
|---|---|---|
| b | SalBoolean | Receives the converted value when the category is supported. |
Returns: SalBoolean. True when the category is supported and processing completes; otherwise, false.
An empty variant becomes false; a non-null date becomes true.
GetDate(d)
Converts a date, string, or empty variant to a SAL date/time.
| Parameter | Type | Description |
|---|---|---|
| d | SalDateTime | Receives the converted value when the category is supported. |
Returns: SalBoolean. True when the category is supported and processing completes; otherwise, false.
GetNumber(num)
Converts a numeric, Boolean, string, or empty variant to a SAL number.
| Parameter | Type | Description |
|---|---|---|
| num | SalNumber | Receives the converted value when the category is supported. |
Returns: SalBoolean. True when the category is supported and processing completes; otherwise, false.
Boolean true converts to -1; an empty variant yields SalNumber.Null.
GetObject(obj)
Assigns an object variant to the supplied automation wrapper.
| Parameter | Type | Description |
|---|---|---|
| obj | SalObject | The destination object wrapper. |
Returns: SalBoolean. True for an object or empty variant; otherwise, false.
An empty variant assigns null to the wrapper.
GetSafeArray(array)
Wraps an array variant as a SalSafeArray.
| Parameter | Type | Description |
|---|---|---|
| array | SalSafeArray | Receives the converted value when the category is supported. |
Returns: SalBoolean. True for an array or empty variant; otherwise, false.
An empty variant creates a wrapper whose Value is null.
GetString(s)
Converts the stored value to a SAL string when it implements IConvertible.
| Parameter | Type | Description |
|---|---|---|
| s | SalString | Receives the converted value when the category is supported. |
Returns: SalBoolean. True when processing completes; false if conversion throws.
Empty and nonconvertible values produce a null SAL string.
MakeOptional()
Replaces the stored value with Type.Missing for an omitted optional argument.
SalType()
Gets the SAL category of the stored value.
Returns: SalNumber. The Sys.SAL_* category code.
SetBlob(s)
Stores the binary byte array from the SAL string.
| Parameter | Type | Description |
|---|---|---|
| s | SalString | The SAL text or binary value to store. |
Returns: SalBoolean. True after assignment.
SetBoolean(b)
Stores the boolean value.
| Parameter | Type | Description |
|---|---|---|
| b | SalBoolean | The Boolean value to store. |
Returns: SalBoolean. True after assignment.
SetDate(d)
Stores the date value.
| Parameter | Type | Description |
|---|---|---|
| d | SalDateTime | The date/time value to store. |
Returns: SalBoolean. True after assignment.
SetNumber(num, vt_type)
Stores a number converted to the requested automation numeric type.
| Parameter | Type | Description |
|---|---|---|
| num | SalNumber | The numeric value to store. |
| vt_type | SalNumber | The supported automation numeric type code. |
Returns: SalBoolean. True after assignment.
Unsupported type codes throw ArgumentException.
SetObject(o)
Stores the attached object from the wrapper.
| Parameter | Type | Description |
|---|---|---|
| o | SalObject | The object wrapper whose Value is stored. |
Returns: SalBoolean. True after assignment.
SetSafeArray(array)
Stores the managed array from the wrapper.
| Parameter | Type | Description |
|---|---|---|
| array | SalSafeArray | The array wrapper whose Value is stored. |
Returns: SalBoolean. True after assignment.
SetString(s)
Stores the string value.
| Parameter | Type | Description |
|---|---|---|
| s | SalString | The SAL text or binary value to store. |
Returns: SalBoolean. True after assignment.
ToByte()
Converts the stored value to a unsigned 8-bit integer.
Returns: Byte. The converted value.
ToCurrency()
Converts the stored value to a COM currency wrapper.
Returns: CurrencyWrapper. The converted value.
ToDateTime()
Converts the stored value to a date/time.
Returns: DateTime. The converted value.
ToDecimal()
Converts the stored value to a decimal number.
Returns: Decimal. The converted value.
ToDouble()
Converts the stored value to a double-precision floating-point number.
Returns: Double. The converted value.
ToInt16()
Converts the stored value to a signed 16-bit integer.
Returns: Int16. The converted value.
ToInt32()
Converts the stored value to a signed 32-bit integer.
Returns: Int32. The converted value.
ToInt64()
Converts the stored value to a signed 64-bit integer.
Returns: Int64. The converted value.
ToSByte()
Converts the stored value to a signed 8-bit integer.
Returns: SByte. The converted value.
ToSingle()
Converts the stored value to a single-precision floating-point number.
Returns: Single. The converted value.
ToUInt16()
Converts the stored value to a byte and widens it to an unsigned 16-bit result.
Returns: UInt16. The converted byte value represented as UInt16.
The implementation uses Convert.ToByte, so values outside the byte range can throw OverflowException.
ToUInt32()
Converts the stored value to a unsigned 32-bit integer.
Returns: UInt32. The converted value.
ToUInt64()
Converts the stored value to a unsigned 64-bit integer.
Returns: UInt64. The converted value.