//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. // //----------------------------------------------------------------------- namespace Microsoft.Isam.Esent.Interop { /// /// A class that encapsulates a JET_TABLEID in a disposable object. /// This opens an existing table. To create a table use the /// JetCreateTable method. /// public class Table : EsentResource { /// /// The session used to open the table. /// private JET_SESID sesid; /// /// The underlying JET_TABLEID. /// private JET_TABLEID tableid; /// /// The name of the table. /// private string name; /// /// Initializes a new instance of the Table class. The table is /// opened from the given database. /// /// The session to use. /// The database to open the table in. /// The name of the table. /// JetOpenTable options. public Table(JET_SESID sesid, JET_DBID dbid, string name, OpenTableGrbit grbit) { this.sesid = sesid; this.name = name; Api.JetOpenTable(this.sesid, dbid, this.name, null, 0, grbit, out this.tableid); this.ResourceWasAllocated(); } /// /// Gets the name of this table. /// public string Name { get { this.CheckObjectIsNotDisposed(); return this.name; } } /// /// Gets the JET_TABLEID that this table contains. /// public JET_TABLEID JetTableid { get { this.CheckObjectIsNotDisposed(); return this.tableid; } } /// /// Implicit conversion operator from a Table to a JET_TABLEID. This /// allows a Table to be used with APIs which expect a JET_TABLEID. /// /// The table to convert. /// The JET_TABLEID of the table. public static implicit operator JET_TABLEID(Table table) { return table.JetTableid; } /// /// Returns a that represents the current . /// /// /// A that represents the current . /// public override string ToString() { return this.name; } /// /// Close the table. /// public void Close() { this.CheckObjectIsNotDisposed(); this.ReleaseResource(); } /// /// Free the underlying JET_TABLEID. /// protected override void ReleaseResource() { Api.JetCloseTable(this.sesid, this.tableid); this.sesid = JET_SESID.Nil; this.tableid = JET_TABLEID.Nil; this.name = null; this.ResourceWasReleased(); } } }