/// <summary> /// Creates a new set of metadata. /// </summary> /// <param name="executionState">The current execution state.</param> /// <param name="items">The initial set of items. If null, no underlying dictionary will be created.</param> public Metadata(IExecutionState executionState, IEnumerable <KeyValuePair <string, object> > items = null) { _ = executionState ?? throw new ArgumentNullException(nameof(executionState)); if (items != null) { Dictionary = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); // If items is an IMetadata, use the raw enumerable so that we don't expand IMetadataValue and Config values if (items is IMetadata metadata) { items = metadata.GetRawEnumerable(); } // Iterate the items, checking for script values foreach (KeyValuePair <string, object> item in items) { if (ScriptMetadataValue.TryGetScriptMetadataValue(item.Key, item.Value, executionState, out ScriptMetadataValue metadataValue)) { Dictionary[item.Key] = metadataValue; } else { Dictionary[item.Key] = item.Value; } } } }