/// <summary> /// Sets the override type for the specified member. /// </summary> /// <param name="key">The member name to setup an override</param> /// <param name="type">Type of the override</param> public void SetOverride(string key, OverrideType type) { if (key == null) { throw new ArgumentNullException(nameof(key)); } YamlNode previousMemberKey = null; YamlNode previousMemberValue = null; if (keyMapping == null) { keyMapping = new Dictionary <string, string>(); } else { string previousMemberName; if (keyMapping.TryGetValue(key, out previousMemberName)) { previousMemberKey = new YamlScalarNode(previousMemberName); node.Children.TryGetValue(previousMemberKey, out previousMemberValue); } keyMapping.Remove(key); } if (overrides == null) { overrides = new Dictionary <string, OverrideType>(); } else { overrides.Remove(key); } // New member name var newMemberName = type == OverrideType.Base ? key : $"{key}{type.ToText()}"; keyMapping[key] = newMemberName; overrides[key] = type; // Remap the original YAML node with the override type if (previousMemberKey != null) { int index = node.Children.IndexOf(previousMemberKey); node.Children.RemoveAt(index); node.Children.Insert(index, new YamlScalarNode(newMemberName), previousMemberValue); } }
/// <inheritdoc/> public override string ToString() { if (IsFrozen) { return($"{{{nameof(AssetContentValueChangeOperation)}: (Frozen)}}"); } try { var sb = new StringBuilder($"{{{nameof(AssetContentValueChangeOperation)}: {(Node as IMemberNode)?.Name ?? Node.Type.Name}"); if (previousOverride != newOverride) { var previousString = previousOverride != OverrideType.Base ? previousOverride.ToText() : "∅"; var newString = newOverride != OverrideType.Base ? newOverride.ToText() : "∅"; sb.Append($"({previousString} -> {newString})"); } switch (ChangeType) { case ContentChangeType.ValueChange: sb.Append($" = {NewValue}}}"); break; case ContentChangeType.CollectionUpdate: sb.Append($"[{Index.Value}] = {NewValue}"); break; case ContentChangeType.CollectionAdd: sb.Append($" ++[{Index.Value}] = {NewValue}}}"); break; case ContentChangeType.CollectionRemove: sb.Append($" --[{Index.Value}] = {NewValue}}}"); break; default: throw new ArgumentOutOfRangeException(); } return(sb.ToString()); } catch (Exception) { return(base.ToString()); } }
/// <summary> /// Sets the override type for the specified member. /// </summary> /// <param name="key">The member name to setup an override</param> /// <param name="type">Type of the override</param> public void SetOverride(string key, OverrideType type) { if (key == null) throw new ArgumentNullException(nameof(key)); YamlNode previousMemberKey = null; YamlNode previousMemberValue = null; if (keyMapping == null) { keyMapping = new Dictionary<string, string>(); } else { string previousMemberName; if (keyMapping.TryGetValue(key, out previousMemberName)) { previousMemberKey = new YamlScalarNode(previousMemberName); node.Children.TryGetValue(previousMemberKey, out previousMemberValue); } keyMapping.Remove(key); } if (overrides == null) { overrides = new Dictionary<string, OverrideType>(); } else { overrides.Remove(key); } // New member name var newMemberName = type == OverrideType.Base ? key : $"{key}{type.ToText()}"; keyMapping[key] = newMemberName; overrides[key] = type; // Remap the original YAML node with the override type if (previousMemberKey != null) { int index = node.Children.IndexOf(previousMemberKey); node.Children.RemoveAt(index); node.Children.Insert(index, new YamlScalarNode(newMemberName), previousMemberValue); } }