//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. // //----------------------------------------------------------------------- namespace Microsoft.Isam.Esent.Interop { using System; /// /// Set a column of a struct type (e.g. Int32/Guid). /// /// Type to set. public abstract class ColumnValueOfStruct : ColumnValue where T : struct, IEquatable { /// /// Internal value. /// private T? internalValue; /// /// Gets the last set or retrieved value of the column. The /// value is returned as a generic object. /// public override object ValueAsObject { get { return BoxedValueCache.GetBoxedValue(this.Value); } } /// /// Gets or sets the value in the struct. /// public T? Value { get { return this.internalValue; } set { this.internalValue = value; this.Error = value == null ? JET_wrn.ColumnNull : JET_wrn.Success; } } /// /// Gets the byte length of a column value, which is zero if column is null, otherwise /// it matches the Size for this fixed-size column. /// public override int Length { get { return this.Value.HasValue ? this.Size : 0; } } /// /// Gets a string representation of this object. /// /// A string representation of this object. public override string ToString() { return this.Value.ToString(); } /// /// Make sure the retrieved data is exactly the size needed for /// the structure. An exception is thrown if there is a mismatch. /// /// The size of the retrieved data. protected void CheckDataCount(int count) { if (this.Size != count) { throw new EsentInvalidColumnException(); } } } }