diff --git a/OneSTools.FileDatabase/Extensions/ObjectExtensions.cs b/OneSTools.FileDatabase/Extensions/ObjectExtensions.cs
new file mode 100644
index 0000000..1a6b06b
--- /dev/null
+++ b/OneSTools.FileDatabase/Extensions/ObjectExtensions.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace OneSTools.FileDatabase.Extensions;
+
+public static class ObjectExtensions
+{
+ public static Guid AsGuid(this object obj)
+ {
+ if (obj is byte[] { Length: 16 } bytes)
+ return new Guid(bytes);
+
+ throw new Exception("failed to convert object to GUID");
+ }
+
+ public static string AsString(this object obj)
+ {
+ if (obj is string value)
+ return value;
+
+ throw new Exception("failed to convert object to string");
+ }
+}
\ No newline at end of file
diff --git a/OneSTools.FileDatabase/FileDatabaseConnection.cs b/OneSTools.FileDatabase/FileDatabaseConnection.cs
index 6187708..731dabe 100644
--- a/OneSTools.FileDatabase/FileDatabaseConnection.cs
+++ b/OneSTools.FileDatabase/FileDatabaseConnection.cs
@@ -3,23 +3,18 @@ using System;
using System.Collections.Generic;
using System.IO;
using OneSTools.FileDatabase.LowLevel;
-using System.Linq;
using OneSTools.FileDatabase.LowLevel.Pages;
using OneSTools.FileDatabase.LowLevel.Files;
using OneSTools.BracketsFile;
using System.Text;
-using System.Data.Common;
-using System.Collections.ObjectModel;
-using System.Data;
namespace OneSTools.FileDatabase
{
///
/// Provides properties and methods for reading 1C file database data
///
- public class FileDatabaseConnection : IDisposable
+ public class FileDatabaseConnection(string path) : IDisposable
{
- private readonly string _path;
private FileDatabaseStream _stream;
private HeaderPage _headerPage;
private FreePagesPage _freePagesPage;
@@ -28,7 +23,7 @@ namespace OneSTools.FileDatabase
///
/// The flag of database opening
///
- public bool Opened { get; private set; } = false;
+ public bool Opened { get; private set; }
///
/// Version of the database file
///
@@ -40,20 +35,19 @@ namespace OneSTools.FileDatabase
///
/// A collection of database tables
///
- public ReadOnlyCollection
Tables { get; private set; } = null;
-
- public FileDatabaseConnection(string path)
- => _path = path;
+ public Tables Tables { get; private set; }
+
+ public Table this[string tableName] => Tables[tableName];
///
- /// Open database file
+ /// Open a database file
///
public void Open()
{
- if (!File.Exists(_path))
- throw new FileNotFoundException("Cannot find a database file", _path);
+ if (!File.Exists(path))
+ throw new FileNotFoundException("Cannot find a database file", path);
- var stream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
_stream = new FileDatabaseStream(stream);
ReadStructure();
@@ -76,7 +70,7 @@ namespace OneSTools.FileDatabase
var tables = new List
();
- for (int i = 0; i < _databaseDescriptionFile.TablesCount; i++)
+ for (var i = 0; i < _databaseDescriptionFile.TablesCount; i++)
{
var tableDefinitionData = _databaseDescriptionFile.ReadTableDefinitionData();
var tableDefinitionStr = Encoding.UTF8.GetString(tableDefinitionData);
@@ -86,11 +80,11 @@ namespace OneSTools.FileDatabase
tables.Add(table);
}
- Tables = tables.AsReadOnly();
+ Tables = new Tables(tables.AsReadOnly());
}
///
- /// Close database file
+ /// Close the database file
///
public void Close()
{
diff --git a/OneSTools.FileDatabase/HighLevel/Table.cs b/OneSTools.FileDatabase/HighLevel/Table.cs
index 0156f11..5cbfe4e 100644
--- a/OneSTools.FileDatabase/HighLevel/Table.cs
+++ b/OneSTools.FileDatabase/HighLevel/Table.cs
@@ -2,13 +2,17 @@
using System.Collections.Generic;
using System.IO;
using System;
+using System.Collections.Immutable;
using OneSTools.FileDatabase.LowLevel;
using System.Collections.ObjectModel;
+using System.Linq;
namespace OneSTools.FileDatabase.HighLevel
{
public class Table
{
+ internal Dictionary FieldNameNumberCache { get; private set; } = new();
+
internal int MaxRowSize { get; private set; }
internal uint DataFilePage { get; private set; }
internal uint UnlimitedLengthDataFilePage { get; private set; }
@@ -17,26 +21,26 @@ namespace OneSTools.FileDatabase.HighLevel
///
/// Internal name of the table
///
- public string Name { get; private set; }
+ public string Name { get; }
///
/// Collection of table fields
///
- public ReadOnlyCollection Fields { get; private set; } = null;
+ public Field[] Fields { get; private set; }
///
/// Collection of table indexes
///
- public ReadOnlyCollection Indexes { get; private set; } = null;
- public bool RecordLock { get; private set; }
+ public Index[] Indexes { get; private set; }
+ public bool RecordLock { get; }
///
/// Collection of table rows
///
- public IReadOnlyList