|
@@ -1,4 +1,5 @@
|
|
|
-using PixiEditor.ChangeableDocument.Changeables.Interfaces;
|
|
|
+using System.Diagnostics.CodeAnalysis;
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Interfaces;
|
|
|
|
|
|
namespace PixiEditor.ChangeableDocument.Changeables;
|
|
|
|
|
@@ -49,14 +50,91 @@ internal class Document : IChangeable, IReadOnlyDocument, IDisposable
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public StructureMember FindMemberOrThrow(Guid guid) => FindMember(guid) ?? throw new ArgumentException("Could not find member with guid " + guid.ToString());
|
|
|
+ /// <summary>
|
|
|
+ /// Check's if a member with the <paramref name="guid"/> exists
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the member</param>
|
|
|
+ /// <returns>True if the member can be found, otherwise false</returns>
|
|
|
+ public bool HasMember(Guid guid)
|
|
|
+ {
|
|
|
+ var list = FindMemberPath(guid);
|
|
|
+ return list.Count > 0;
|
|
|
+ }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Check's if a member with the <paramref name="guid"/> exists and is of type <typeparamref name="T"/>
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the member</param>
|
|
|
+ /// <returns>True if the member can be found and is of type <typeparamref name="T"/>, otherwise false</returns>
|
|
|
+ public bool HasMember<T>(Guid guid) where T : StructureMember
|
|
|
+ {
|
|
|
+ var list = FindMemberPath(guid);
|
|
|
+ return list.Count > 0 && list[0] is T;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Find's the member with the <paramref name="guid"/> or throws a ArgumentException if not found
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the member</param>
|
|
|
+ /// <exception cref="ArgumentException">Thrown if the member could not be found</exception>
|
|
|
+ public StructureMember FindMemberOrThrow(Guid guid) => FindMember(guid) ?? throw new ArgumentException($"Could not find member with guid '{guid}'");
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Find's the member of type <typeparamref name="T"/> with the <paramref name="guid"/> or throws an exception
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the member</param>
|
|
|
+ /// <exception cref="ArgumentException">Thrown if the member could not be found</exception>
|
|
|
+ /// <exception cref="InvalidCastException">Thrown if the member is not of type <typeparamref name="T"/></exception>
|
|
|
+ public T FindMemberOrThrow<T>(Guid guid) where T : StructureMember => (T)FindMember(guid)!;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Find's the member with the <paramref name="guid"/> or returns null if not found
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the member</param>
|
|
|
public StructureMember? FindMember(Guid guid)
|
|
|
{
|
|
|
var list = FindMemberPath(guid);
|
|
|
return list.Count > 0 ? list[0] : null;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Tries finding the member with the <paramref name="guid"/> and returns if it was found
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the <paramref name="member"/></param>
|
|
|
+ /// <param name="member">The member</param>
|
|
|
+ /// <returns>True if the member could be found, otherwise false</returns>
|
|
|
+ public bool TryFindMember(Guid guid, [NotNullWhen(true)] out StructureMember? member)
|
|
|
+ {
|
|
|
+ var list = FindMemberPath(guid);
|
|
|
+ if (list.Count == 0)
|
|
|
+ {
|
|
|
+ member = null;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ member = list[0];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Tries finding the member with the <paramref name="guid"/> and returns if it was found
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="guid">The <see cref="StructureMember.GuidValue"/> of the <paramref name="member"/></param>
|
|
|
+ /// <param name="member">The member</param>
|
|
|
+ /// <typeparam name="T">The type of the <see cref="StructureMember"/></typeparam>
|
|
|
+ /// <returns>True if the member could be found and is of type <typeparamref name="T"/>, otherwise false</returns>
|
|
|
+ public bool TryFindMember<T>(Guid guid, [NotNullWhen(true)] out T? member) where T : StructureMember
|
|
|
+ {
|
|
|
+ if (!TryFindMember(guid, out var structureMember) || structureMember is not T cast)
|
|
|
+ {
|
|
|
+ member = null;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ member = cast;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
public (StructureMember, Folder) FindChildAndParentOrThrow(Guid childGuid)
|
|
|
{
|
|
|
var path = FindMemberPath(childGuid);
|