2using System.Collections.Generic;
12 int num =
Hash(s) & 0x1F;
14 if ((
m_mask & num2) != 0) {
20 public void Add(
string s) {
21 int num =
Hash(s) & 0x1F;
27 static int Hash(
string s) {
28 int length = s.Length;
29 return s[0] + s[length >> 1] + s[length - 1];
45#pragma warning disable CS0649
47#pragma warning restore CS0649
65 throw new InvalidOperationException(
"Cannot change name of a read-only database object.");
68 if (value.Length >
Type.NameLengthLimit) {
69 throw new InvalidOperationException(
70 $
"Name \"{value}\" is too long, maximum name length for database object of type \"{Type.Name}\" is {Type.NameLengthLimit}."
75 if (explicitNestingChild.
Name == value) {
76 throw new InvalidOperationException(
77 $
"Database object \"{explicitNestingChild.Name}\" is already nested in parent database object \"{NestingParent.Name}\"."
91 throw new InvalidOperationException(
"Cannot change description of a read-only database object.");
94 throw new ArgumentNullException(nameof(value),
"Description cannot be null.");
104 throw new InvalidOperationException(
"Cannot change value of a read-only database object.");
106 if (!
Type.SupportsValue) {
107 throw new InvalidOperationException($
"Database objects of type \"{Type.Name}\" do not support values.");
110 throw new ArgumentNullException(nameof(value),
"Value cannot be null.");
122 throw new InvalidOperationException(
"Cannot change nesting parent of a read-only database object.");
130 throw new InvalidOperationException(
"Root database object cannot be nested.");
132 if (!
Type.AllowedNestingParents.Contains(value.Type)) {
133 throw new InvalidOperationException($
"Database object of type {Type.Name} cannot be nested in {value.Type.Name}.");
136 || value.EffectivelyInheritsFrom(
this)
138 || value.IsNestedIn(
this)) {
139 throw new InvalidOperationException(
140 $
"Cannot set nesting parent of database object \"{Name}\" to database object \"{value.Name}\" because it would create recursive nesting/inheritance."
143 if (value.FindExplicitNestedChild(
Name,
null,
true,
false) !=
null) {
144 throw new InvalidOperationException(
145 $
"Another database object with name \"{Name}\" is already nested in database object \"{value.Name}\"."
151 throw new InvalidOperationException(
"DatabaseObject internal error: nested DatabaseObject not found in container.");
159 if (value.m_database !=
null) {
160 value.m_database.AddDatabaseObject(
this,
true);
181 throw new InvalidOperationException(
"Cannot change inheritance parent of a read-only database object.");
188 || value.EffectivelyInheritsFrom(
this)
189 || value.IsNestedIn(
this)
191 throw new InvalidOperationException(
192 $
"Cannot set inheritance parent of database object \"{Name}\" to database object \"{value.Name}\" because it would create recursive nesting/inheritance."
195 if (!
Type.AllowedInheritanceParents.Contains(value.Type)) {
196 throw new InvalidOperationException($
"Database object of type {Type.Name} cannot inherit from {value.Type.Name}.");
215 return NestingParent.EffectiveInheritanceParent?.FindEffectiveNestedChild(
Name,
null,
true,
false);
224 if (implicitInheritanceParent ==
null) {
243 if (effectiveInheritanceParent ==
null) {
261 throw new InvalidOperationException($
"InitializeRelations of DatabaseObjectType \"{databaseObjectType.Name}\" not called.");
293 || databaseObject.
Type == type) {
294 yield
return databaseObject;
296 if (!directChildrenOnly) {
298 yield
return explicitNestingChild;
306 if (explicitNestingChild.
Name == name) {
307 return explicitNestingChild;
310 if (throwIfNotFound) {
311 throw new InvalidOperationException($
"Required database object \"{name}\" not found in database object \"{Name}\"");
318 if (explicitInheritanceParent !=
null) {
319 if (explicitInheritanceParent != databaseObject) {
329 if (implicitInheritanceParent !=
null) {
330 if (implicitInheritanceParent != databaseObject) {
340 if (effectiveInheritanceParent !=
null) {
341 if (effectiveInheritanceParent != databaseObject) {
350 if (directChildrenOnly) {
353 || item.
Type == type) {
361 || databaseObject.
Type == type) {
362 yield
return databaseObject;
365 yield
return effectiveNestingChild;
373 if (effectiveNestingChild.
Name == name) {
374 return effectiveNestingChild;
377 if (throwIfNotFound) {
378 throw new InvalidOperationException($
"Required database object \"{name}\" not found in database object \"{Name}\"");
390 if (databaseObject ==
null) {
398 if (databaseObject ==
null
403 databaseObject.Value = value;
409 return $
"{Name} in {NestingParent}";
415 if (databaseObject.
Value !=
null
416 && !(databaseObject.
Value is T)) {
418 $
"Database object \"{databaseObject.Name}\" has invalid type \"{databaseObject.Value.GetType().FullName}\", required type is \"{typeof(T).FullName}\"."
421 return (T)databaseObject.
Value;
425 if (
Type.AllowedNestingChildren.Count != 0) {
428 names.
Add(explicitNestingChild.
Name);
429 yield
return explicitNestingChild;
433 if (effectiveInheritanceParent !=
null) {
static int Hash(string s)
bool ExplicitlyInheritsFrom(DatabaseObject databaseObject)
DatabaseObjectType m_databaseObjectType
DatabaseObject FindEffectiveNestedChild(string name, DatabaseObjectType type, bool directChildrenOnly, bool throwIfNotFound)
List< DatabaseObject > InternalNestingChildren
DatabaseObject ExplicitInheritanceRoot
T GetNestedValue< T >(string name)
bool ImplicitlyInheritsFrom(DatabaseObject databaseObject)
T CastValue< T >(DatabaseObject databaseObject)
bool EffectivelyInheritsFrom(DatabaseObject databaseObject)
IEnumerable< DatabaseObject > InternalGetEffectiveNestingChildren(StringBin names, DatabaseObjectType type)
DatabaseObject EffectiveInheritanceParent
override string ToString()
DatabaseObject m_nestingParent
IEnumerable< DatabaseObject > GetEffectiveNestingChildren(DatabaseObjectType type, bool directChildrenOnly)
DatabaseObject(DatabaseObjectType databaseObjectType, string name, object value)
List< DatabaseObject > m_nestingChildren
DatabaseObject m_explicitInheritanceParent
void SetNestedValue< T >(string name, T value)
DatabaseObject ImplicitInheritanceRoot
DatabaseObject FindExplicitNestedChild(string name, DatabaseObjectType type, bool directChildrenOnly, bool throwIfNotFound)
DatabaseObject(DatabaseObjectType databaseObjectType, string name)
bool IsNestedIn(DatabaseObject databaseObject)
DatabaseObject ExplicitInheritanceParent
DatabaseObject ImplicitInheritanceParent
DatabaseObject NestingParent
DatabaseObject(DatabaseObjectType databaseObjectType, Guid guid, string name, object value)
DatabaseObject NestingRoot
DatabaseObject EffectiveInheritanceRoot
IEnumerable< DatabaseObject > GetExplicitNestingChildren(DatabaseObjectType type, bool directChildrenOnly)