// ---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
//
// ---------------------------------------------------------------------
namespace Microsoft.Database.Isam
{
using System;
using System.Collections;
///
/// A Field Value Collection represents the set of field values that are in
/// a given field in a given record. It can be used to efficiently
/// navigate those field values.
///
public class FieldValueCollection : CollectionBase
{
///
/// The columnid
///
private readonly Columnid columnid;
///
/// The read only
///
private bool readOnly = false;
///
/// Initializes a new instance of the class.
///
/// The columnid.
internal FieldValueCollection(Columnid columnid)
{
this.columnid = columnid;
}
///
/// Gets the column ID of the column for which these field values were set
/// in the record
///
///
/// The columnid.
///
public Columnid Columnid
{
get
{
return this.columnid;
}
}
///
/// Gets the name of the column for which these field values were set in the
/// record
///
///
/// The name.
///
public string Name
{
get
{
return this.columnid.Name;
}
}
///
/// Gets the type of the column for which these field values were set in the
/// record
///
///
/// The type.
///
public Type Type
{
get
{
return this.columnid.Type;
}
}
///
/// Gets or sets a value indicating whether this field value collection cannot be changed
///
///
/// true if [read only]; otherwise, false.
///
public bool ReadOnly
{
get
{
return this.readOnly;
}
set
{
this.CheckReadOnly();
this.readOnly = value;
}
}
///
/// Gets or sets the element at the specified index.
///
/// The index.
/// The specific element at that position.
public object this[int index]
{
get
{
return this.List[index];
}
set
{
this.CheckReadOnly();
this.List[index] = value;
}
}
///
/// Adds the specified value.
///
/// The value.
public void Add(object value)
{
List.Add(value);
}
///
/// Determines the index of a specific item in the .
///
/// The object to locate in the .
///
/// The index of if found in the list; otherwise, -1.
///
public int IndexOf(object value)
{
return List.IndexOf(value);
}
///
/// Inserts an item to the at the specified index.
///
/// The zero-based index at which should be inserted.
/// The object to insert into the .
public void Insert(int index, object value)
{
List.Insert(index, value);
}
///
/// Removes the first occurrence of a specific object from the .
///
/// The object to remove from the .
public void Remove(object value)
{
List.Remove(value);
}
///
/// Determines whether the contains a specific value.
///
/// The object to locate in the .
///
/// true if the is found in the ; otherwise, false.
///
public bool Contains(object value)
{
return List.Contains(value);
}
///
/// Performs additional custom processes when clearing the contents of the instance.
///
protected override void OnClear()
{
this.CheckReadOnly();
}
///
/// Performs additional custom processes before inserting a new element into the instance.
///
/// The zero-based index at which to insert .
/// The new value of the element at .
protected override void OnInsert(int index, object value)
{
this.CheckReadOnly();
}
///
/// Performs additional custom processes when removing an element from the instance.
///
/// The zero-based index at which can be found.
/// The value of the element to remove from .
protected override void OnRemove(int index, object value)
{
this.CheckReadOnly();
}
///
/// Performs additional custom processes before setting a value in the instance.
///
/// The zero-based index at which can be found.
/// The value to replace with .
/// The new value of the element at .
protected override void OnSet(int index, object oldValue, object newValue)
{
this.CheckReadOnly();
}
///
/// Performs additional custom processes when validating a value.
///
/// The object to validate.
/// value must be of type + Type + or of type + typeof(System.DBNull);value
protected override void OnValidate(object value)
{
if (value.GetType() != Type && value.GetType() != typeof(System.DBNull))
{
throw new ArgumentException(
"value must be of type " + Type + " or of type " + typeof(System.DBNull),
"value");
}
}
///
/// Checks the read only.
///
/// this field value collection cannot be changed
private void CheckReadOnly()
{
if (this.ReadOnly)
{
throw new NotSupportedException("this field value collection cannot be changed");
}
}
}
}