2using System.Collections.Generic;
19 List<DatabaseObjectType> objectTypes = databaseObjectTypes.ToList();
20 if (!objectTypes.Contains(root.
Type)) {
21 throw new Exception(
"Database root has invalid database object type.");
24 throw new Exception(
"Database root cannot be nested.");
28 m_root.m_database =
this;
33 if (databaseObjectType.
Name == name) {
34 return databaseObjectType;
37 if (throwIfNotFound) {
38 throw new Exception($
"Required database object type \"{name}\" not found.");
47 && value.Type != type) {
48 throw new InvalidOperationException($
"Database object {guid} has invalid type. Expected {type.Name}, found {value.Type.Name}.");
51 else if (throwIfNotFound) {
52 throw new InvalidOperationException($
"Required database object {guid} not found.");
58 Root.FindExplicitNestedChild(name, type,
false, throwIfNotFound);
61 foreach (
DatabaseObject explicitNestingChild
in Root.GetExplicitNestingChildren(
null,
false)) {
62 if (explicitNestingChild.
Value !=
null
63 && !typesList.Contains(explicitNestingChild.
Value.GetType())) {
64 typesList.Add(explicitNestingChild.
Value.GetType());
71 throw new InvalidOperationException(
"Internal error: database object is already in a database.");
74 throw new InvalidOperationException($
"Database object type \"{databaseObject.Type.Name}\" is not supported by the database.");
76 if (checkThatGuidsAreUnique) {
77 if (databaseObject.
Guid != Guid.Empty
79 throw new InvalidOperationException($
"Database object {databaseObject.Guid} is already present in the database.");
82 if (explicitNestingChild.
Guid != Guid.Empty
84 throw new InvalidOperationException($
"Database object {explicitNestingChild.Guid} is already present in the database.");
88 databaseObject.m_database =
this;
89 if (databaseObject.
Guid != Guid.Empty) {
99 throw new InvalidOperationException(
"Internal error: database object is not in the database.");
101 databaseObject.m_database =
null;
102 if (databaseObject.
Guid != Guid.Empty
104 throw new InvalidOperationException(
"Internal error: database object not in dictionary.");
void AddDatabaseObject(DatabaseObject databaseObject, bool checkThatGuidsAreUnique)
DatabaseObjectType FindDatabaseObjectType(string name, bool throwIfNotFound)
Database(DatabaseObject root, IEnumerable< DatabaseObjectType > databaseObjectTypes)
Dictionary< Guid, DatabaseObject > m_databaseObjectsByGuid
void RemoveDatabaseObject(DatabaseObject databaseObject)
ReadOnlyList< DatabaseObjectType > m_databaseObjectTypes
IList< DatabaseObjectType > DatabaseObjectTypes
void FindUsedValueTypes(List< Type > typesList)
DatabaseObject FindDatabaseObject(Guid guid, DatabaseObjectType type, bool throwIfNotFound)
DatabaseObject FindDatabaseObject(string name, DatabaseObjectType type, bool throwIfNotFound)
DatabaseObject NestingParent
IEnumerable< DatabaseObject > GetExplicitNestingChildren(DatabaseObjectType type, bool directChildrenOnly)