/// <summary> /// Removes attached metadata from the given YAML path. /// </summary> /// <param name="path">The path at which to remove metadata.</param> public void Remove(YamlAssetPath path) { if (isAttached) { throw new InvalidOperationException("Cannot modify a YamlAssetMetadata after it has been attached."); } metadata.Remove(path); }
/// <summary> /// Attaches the given metadata value to the given YAML path. /// </summary> /// <param name="path">The path at which to attach metadata.</param> /// <param name="value">The metadata to attach.</param> public void Set([NotNull] YamlAssetPath path, T value) { if (isAttached) { throw new InvalidOperationException("Cannot modify a YamlAssetMetadata after it has been attached."); } metadata[path] = value; }
public YamlAssetPath Append([CanBeNull] YamlAssetPath other) { var result = new YamlAssetPath(elements); if (other != null) { result.elements.AddRange(other.elements); } return(result); }
public static YamlAssetPath FromMemberPath([NotNull] MemberPath path, object root) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var result = new YamlAssetPath(); var clone = new MemberPath(); foreach (var item in path.Decompose()) { if (item.MemberDescriptor != null) { clone.Push(item.MemberDescriptor); var member = item.MemberDescriptor.Name; result.PushMember(member); } else { object index = null; if (item is MemberPath.ArrayPathItem arrayItem) { clone.Push(arrayItem.Descriptor, arrayItem.Index); index = arrayItem.Index; } if (item is MemberPath.CollectionPathItem collectionItem) { clone.Push(collectionItem.Descriptor, collectionItem.Index); index = collectionItem.Index; } if (item is MemberPath.DictionaryPathItem dictionaryItem) { clone.Push(dictionaryItem.Descriptor, dictionaryItem.Key); index = dictionaryItem.Key; } if (!CollectionItemIdHelper.TryGetCollectionItemIds(clone.GetValue(root), out CollectionItemIdentifiers ids)) { result.PushIndex(index); } else { var id = ids[index]; // Create a new id if we don't have any so far if (id == ItemId.Empty) { id = ItemId.New(); } result.PushItemId(id); } } } return(result); }
/// <summary> /// Indicates whether the current path represents the same path of another object. /// </summary> /// <param name="other">An object to compare with this path.</param> /// <returns><c>true</c> if the current path matches the <paramref name="other"/> parameter; otherwise, <c>false</c>.</returns> public bool Match(YamlAssetPath other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (Elements.Count != other.Elements.Count) { return(false); } return(Elements.SequenceEqual(other.Elements)); }
public bool StartsWith([NotNull] YamlAssetPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (path.elements.Count > elements.Count) { return(false); } for (var i = 0; i < path.Elements.Count; ++i) { if (!Elements[i].Equals(path.Elements[i])) { return(false); } } return(true); }
public YamlAssetPath Clone() { var clone = new YamlAssetPath(elements); return(clone); }
/// <inheritdoc/> object IYamlAssetMetadata.TryGet(YamlAssetPath path) => TryGet(path);
/// <inheritdoc/> void IYamlAssetMetadata.Set(YamlAssetPath path, object value) => Set(path, (T)value);
/// <summary> /// Tries to retrieve the metadata for the given path. /// </summary> /// <param name="path">The path at which to retrieve metadata.</param> /// <returns>The metadata attached to the given path, or the default value of <typeparamref name="T"/> if no metadata is attached at the given path.</returns> public T TryGet([NotNull] YamlAssetPath path) { metadata.TryGetValue(path, out T value); return(value); }