TryGetTable Method

Overview

The TryGetTable method attempts to retrieve an observable data table from an IObservableDataSet by its name. The method returns a Boolean value indicating whether the table exists and never throws an exception if the table is missing.

This method is the recommended way to safely access optional tables in an observable data set. It avoids direct interaction with the underlying tables dictionary and preserves the invariant that table mutations must go through dedicated API methods.

Declaration

/// <summary>
/// Tries to get observable table by name
/// </summary>
/// <param name="observableDataSet">Observable data set</param>
/// <param name="tableName">Table name</param>
/// <param name="observableDataTable">Observable table</param>
/// <returns>True if found, otherwise false</returns>
public static bool TryGetTable(this IObservableDataSet? observableDataSet, string tableName, out IObservableDataTable? observableDataTable)

Namespace and Assembly

Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll

Usage Example

// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();

// 2. Create Department observable table
IObservableDataTable departmentObservableDataTable = observableDataSet.AddNewTable("Department");
departmentObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentObservableDataTable.AddColumn("Name", DataTypeNames.STRING);

IObservableDataRow departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 1;
departmentObservableDataRow["Name"] = "Reception";

// 3. Safely access an optional observable table
observableDataSet.TryGetTable("Department", out IObservableDataTable? retreivedDepartmentObservableDataTable);
observableDataSet.TryGetTable("Employee", out IObservableDataTable? retreivedEmployeeObservableDataTable);

// At this point:
// retreivedDepartmentObservableDataTable is not null
// retreivedEmployeeObservableDataTable is null

Notes

 

Table of Content POCO DataSet Observable Data Set Members

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.