4 using System.Collections.Immutable;
5 using System.Diagnostics;
12 public readonly
static ImmutableHashSet<Type>
Types;
15 Types = ReflectionUtils.GetDerivedNonAbstract<
Prefab>().ToImmutableHashSet();
18 private static bool potentialCallFromConstructor =
false;
21 if (!potentialCallFromConstructor) {
return; }
22 StackTrace st =
new StackTrace(skipFrames: 2, fNeedFileInfo:
false);
23 for (
int i = st.FrameCount - 1; i >= 0; i--)
25 if (st.GetFrame(i)?.GetMethod() is { IsConstructor: true, DeclaringType: { } declaringType }
26 &&
Types.Contains(declaringType))
28 throw new Exception(
"Called disallowed method from within a prefab's constructor!");
31 potentialCallFromConstructor =
false;
42 potentialCallFromConstructor =
true;
44 Identifier = identifier;
45 if (Identifier.IsEmpty) {
throw new ArgumentException($
"Error creating {GetType().Name}: Identifier cannot be empty"); }
50 potentialCallFromConstructor =
true;
52 Identifier = DetermineIdentifier(element!);
53 if (Identifier.IsEmpty) {
throw new ArgumentException($
"Error creating {GetType().Name}: Identifier cannot be empty"); }
58 return element.GetAttributeIdentifier(
"identifier", Identifier.Empty);
Base class for content file types, which are loaded from filelist.xml via reflection....
readonly ContentPath Path
readonly ContentPackage ContentPackage
static readonly ImmutableHashSet< Type > Types
Prefab(ContentFile file, ContentXElement element)
virtual Identifier DetermineIdentifier(XElement element)
readonly ContentFile ContentFile
Prefab(ContentFile file, Identifier identifier)
static void DisallowCallFromConstructor()
readonly Identifier Identifier