Small enhancements introduced from Rbx2Source migration.

This commit is contained in:
CloneTrooper1019
2020-09-21 13:29:31 -05:00
parent 7252e96c03
commit d1535c9a15
9 changed files with 78 additions and 33 deletions

View File

@ -56,6 +56,9 @@ namespace RobloxFiles
/// <summary>Indicates whether this Instance is a Service.</summary>
public bool IsService { get; internal set; }
/// <summary>Indicates whether this Instance has been destroyed.</summary>
public bool Destroyed { get; internal set; }
/// <summary>A list of CollectionService tags assigned to this Instance.</summary>
public List<string> Tags { get; } = new List<string>();
@ -200,12 +203,9 @@ namespace RobloxFiles
if (Parent == this)
throw new InvalidOperationException($"Attempt to set {Name} as its own parent");
lock (ParentUnsafe)
{
ParentUnsafe?.Children.Remove(this);
value?.Children.Add(this);
ParentUnsafe = value;
}
ParentUnsafe?.Children.Remove(this);
value?.Children.Add(this);
ParentUnsafe = value;
}
}
@ -418,6 +418,28 @@ namespace RobloxFiles
return result;
}
/// <summary>
/// Disposes of this instance and its descendants, and locks its parent.
/// All property bindings, tags, and attributes are cleared.
/// </summary>
public void Destroy()
{
Destroyed = true;
props.Clear();
Parent = null;
ParentLocked = true;
Tags?.Clear();
Attributes?.Clear();
while (Children.Any())
{
var child = Children.First();
child.Destroy();
}
}
/// <summary>
/// Returns the first child of this Instance which derives from the provided type <typeparamref name="T"/>.
/// If the instance is not found, this returns null.