Improvements and bug fixes
- Added some more methods to the Instance class to make instance queries more powerful. - Fixed a bug where comment nodes were being processed by the XmlFileReader
This commit is contained in:
parent
eea5022e41
commit
0a5bb69486
@ -131,6 +131,22 @@ namespace RobloxFiles
|
|||||||
return classType.IsAssignableFrom(myType);
|
return classType.IsAssignableFrom(myType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to cast this Instance to an inherited class of type '<typeparamref name="T"/>'.
|
||||||
|
/// Returns null if the instance cannot be casted to the provided type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of Instance to cast to.</typeparam>
|
||||||
|
/// <returns>The instance as the type '<typeparamref name="T"/>' if it can be converted, or null.</returns>
|
||||||
|
public T Cast<T>() where T : Instance
|
||||||
|
{
|
||||||
|
T result = null;
|
||||||
|
|
||||||
|
if (IsA<T>())
|
||||||
|
result = this as T;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The parent of this Instance, or null if the instance is the root of a tree.<para/>
|
/// The parent of this Instance, or null if the instance is the root of a tree.<para/>
|
||||||
/// Setting the value of this property will throw an exception if:<para/>
|
/// Setting the value of this property will throw an exception if:<para/>
|
||||||
@ -163,7 +179,7 @@ namespace RobloxFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a snapshot of the Instances currently parented to this Instance, as an array.
|
/// Returns an array containing all the children of this Instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Instance[] GetChildren()
|
public Instance[] GetChildren()
|
||||||
{
|
{
|
||||||
@ -171,7 +187,20 @@ namespace RobloxFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a snapshot of the Instances that are descendants of this Instance, as an array.
|
/// Returns an array containing all the children of this Instance, whose type is '<typeparamref name="T"/>'.
|
||||||
|
/// </summary>
|
||||||
|
public T[] GetChildrenOfType<T>() where T : Instance
|
||||||
|
{
|
||||||
|
T[] ofType = GetChildren()
|
||||||
|
.Where(child => child.IsA<T>())
|
||||||
|
.Cast<T>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
return ofType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns an array containing all the descendants of this Instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Instance[] GetDescendants()
|
public Instance[] GetDescendants()
|
||||||
{
|
{
|
||||||
@ -190,6 +219,19 @@ namespace RobloxFiles
|
|||||||
return results.ToArray();
|
return results.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns an array containing all the descendants of this Instance, whose type is '<typeparamref name="T"/>'.
|
||||||
|
/// </summary>
|
||||||
|
public T[] GetDescendantsOfType<T>() where T : Instance
|
||||||
|
{
|
||||||
|
T[] ofType = GetDescendants()
|
||||||
|
.Where(desc => desc.IsA<T>())
|
||||||
|
.Cast<T>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
return ofType;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the first child of this Instance whose Name is the provided string name.
|
/// Returns the first child of this Instance whose Name is the provided string name.
|
||||||
/// If the instance is not found, this returns null.
|
/// If the instance is not found, this returns null.
|
||||||
@ -291,7 +333,7 @@ namespace RobloxFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the first ancestor of this Instance which derives from the provided type T.
|
/// Returns the first ancestor of this Instance which derives from the provided type <typeparamref name="T"/>.
|
||||||
/// If the instance is not found, this returns null.
|
/// If the instance is not found, this returns null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The Name of the Instance to find.</param>
|
/// <param name="name">The Name of the Instance to find.</param>
|
||||||
@ -349,7 +391,7 @@ namespace RobloxFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the first child of this Instance which derives from the provided type T.
|
/// 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.
|
/// If the instance is not found, this returns null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="recursive">Whether this should search descendants as well.</param>
|
/// <param name="recursive">Whether this should search descendants as well.</param>
|
||||||
|
@ -75,6 +75,9 @@ namespace RobloxFiles.XmlFormat
|
|||||||
|
|
||||||
foreach (XmlNode propNode in propsNode.ChildNodes)
|
foreach (XmlNode propNode in propsNode.ChildNodes)
|
||||||
{
|
{
|
||||||
|
if (propNode.NodeType == XmlNodeType.Comment)
|
||||||
|
continue;
|
||||||
|
|
||||||
string propType = propNode.Name;
|
string propType = propNode.Name;
|
||||||
XmlNode propName = propNode.Attributes.GetNamedItem("name");
|
XmlNode propName = propNode.Attributes.GetNamedItem("name");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user