ConvertingDictionary Class
A dictionary with metadata type conversion superpowers.
Namespace
Statiq.Common
Interfaces
  • IMetadataDictionary
  • IDictionary<string, object>
  • ICollection<KeyValuePair<string, object>>
  • IMetadata
  • IReadOnlyDictionary<string, object>
  • IReadOnlyCollection<KeyValuePair<string, object>>
  • IEnumerable<KeyValuePair<string, object>>
  • IEnumerable
Base Types
  • object
graph BT Type-->Base0["object"] Type-.->Interface0["IMetadataDictionary"] click Interface0 "/api/Statiq.Common/IMetadataDictionary" Type-.->Interface1["IDictionary<string, object>"] Type-.->Interface2["ICollection<KeyValuePair<string, object>>"] Type-.->Interface3["IMetadata"] click Interface3 "/api/Statiq.Common/IMetadata" Type-.->Interface4["IReadOnlyDictionary<string, object>"] Type-.->Interface5["IReadOnlyCollection<KeyValuePair<string, object>>"] Type-.->Interface6["IEnumerable<KeyValuePair<string, object>>"] Type-.->Interface7["IEnumerable"] Type["ConvertingDictionary"] class Type type-node

Syntax

public class ConvertingDictionary : IMetadataDictionary, IDictionary<string, object>, 
    ICollection<KeyValuePair<string, object>>, IMetadata, IReadOnlyDictionary<string, object>, 
    IReadOnlyCollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, 
    IEnumerable

Remarks

This class wraps an underlying IDictionary<TKey, TValue> but uses the provided IExecutionContext to perform type conversions when requesting values.

Constructors

Properties

Name Property Type Summary
Count int
The count of metadata.
IsReadOnly bool
Keys ICollection<string>
A collection of keys in the metadata.
this[string] object
Gets a metadata value given the specified metadata key.
Values ICollection<object>
A collection of values in the metadata.

Methods

Name Return Value Summary
Add(KeyValuePair<string, object>) void
Add(string, object) void
Clear() void
Contains(KeyValuePair<string, object>) bool
ContainsKey(string) bool
Whether or not the metadata contains the specified key.
CopyTo(KeyValuePair<string, object>[], int) void
GetEnumerator() IEnumerator<KeyValuePair<string, object>>
GetRawEnumerator() IEnumerator<KeyValuePair<string, object>>
Enumerates raw key-value pairs (I.e., the values have not been expanded similar to TryGetRaw(string, object)).
Remove(KeyValuePair<string, object>) bool
Remove(string) bool
TryGetRaw(string, object) bool
Tries to get the raw value for the specified key. This method will not materialize IMetadataValue values or process script strings the way the TryGetValue<TValue>(IMetadata, string, TValue) extension and other get methods will. A System.Collections.Generic.KeyNotFoundException will be thrown for missing keys.
TryGetValue(string, object) bool
Attempts to get a value from metadata.

Extension Methods

Name Value Summary
AddOrReplaceRange<string, object>(IEnumerable<KeyValuePair<string, object>>) void
AddRange<KeyValuePair<string, object>>(IEnumerable<KeyValuePair<string, object>>) void
Adds a range of values to a collection.
AddRange<KeyValuePair<string, object>>(KeyValuePair<string, object>[]) void
Adds a range of values to a collection.
Concat<KeyValuePair<string, object>>(KeyValuePair<string, object>) IEnumerable<T>
ContainsAnyKeys<string, object>(IEnumerable<string>) bool
Determines whether the dictionary contains all the specified keys.
ContainsAnyKeys<string, object>(string[]) bool
Determines whether the dictionary contains all the specified keys.
ContainsKeys<string, object>(IEnumerable<string>) bool
Determines whether the dictionary contains all the specified keys.
ContainsKeys<string, object>(string[]) bool
Determines whether the dictionary contains all the specified keys.
FilterMetadata(string[]) IMetadata
Gets a new filtered IMetadata containing only the specified keys and their values. If a key is not present in the current metadata, it will be ignored and will not be copied to the new metadata object.
Get(string, object) object
Gets the value for the specified key. This method never throws an exception. It will return the specified default value or null if the key is not found or is null.
Get<T>(string, T) T
Gets the value for the specified key. This method never throws an exception. It will return the specified default value if the key is not found or is null.
Get<T>(string) T
Gets the value for the specified key converted to the specified type. This method never throws an exception. It will return default(T) if the key is not found, is null, or the value cannot be converted to T.
GetBool(string, bool) bool
Gets the value for the specified key converted to a bool. This method never throws an exception. It will return the specified default value if the key is not found.
GetDateTime(string, DateTime) DateTime
Gets the value for the specified key converted to a DateTime. This method never throws an exception. It will return the specified default value if the key is not found.
GetDateTimeOffset(string, DateTimeOffset) DateTimeOffset
Gets the value for the specified key converted to a DateTimeOffset. This method never throws an exception. It will return the specified default value if the key is not found.
GetDocument(string, IDocument) IDocument
Gets the value for the specified key converted to a IDocument. This method never throws an exception. It will return null if the key is not found.
GetDocumentList(string) DocumentList<IDocument>
Gets the value for the specified key converted to a DocumentList<TDocument>. This method never throws an exception. It will return an empty list if the key is not found or if the key is found but contains no items that can be converted to IDocument.
GetDocumentList<TDocument>(string) DocumentList<TDocument>
Gets the value for the specified key converted to a DocumentList<TDocument>. This method never throws an exception. It will return an empty list if the key is not found or if the key is found but contains no items that can be converted to the specified document type.
GetDocuments(string, IReadOnlyList<IDocument>) IEnumerable<IDocument>
Gets the value for the specified key converted to a IReadOnlyList<IDocument>. This method never throws an exception. It will return null if the key is not found and an empty list if the key is found but contains no items that can be converted to IDocument.
GetDocuments<TDocument>(string, IReadOnlyList<TDocument>) IEnumerable<TDocument>
Gets the value for the specified key converted to a IReadOnlyList<TDocument>. This method never throws an exception. It will return null if the key is not found and an empty list if the key is found but contains no items that can be converted to the specified document type.
GetDynamic(string, object) dynamic
Gets the value associated with the specified key as a dynamic object. This is equivalent to calling as dynamic to cast the value.
GetEnumerable() IEnumerable<KeyValuePair<string, object>>
Gets an enumerable that enumerates key-value pairs.
GetInt(string, int) int
Gets the value for the specified key converted to an int. This method never throws an exception. It will return the specified default value if the key is not found.
GetList<T>(string, IReadOnlyList<T>) IReadOnlyList<T>
Gets the value for the specified key converted to a IReadOnlyList<T>. This method never throws an exception. It will return the specified default value if the key is not found. Note that if the value is atomic, the conversion operation will succeed and return a list with one item.
GetMetadata(string, IMetadata) IMetadata
Gets the value for the specified key converted to a nested IMetadata. This method never throws an exception. It will return null if the key is not found.
GetNext<KeyValuePair<string, object>>(KeyValuePair<string, object>, IEqualityComparer<KeyValuePair<string, object>>) T
GetNext<KeyValuePair<string, object>>(KeyValuePair<string, object>) T
GetPath(string, NormalizedPath) NormalizedPath
Gets the value for the specified key converted to a NormalizedPath. This method never throws an exception. It will return the specified default value if the key is not found.
GetPrevious<KeyValuePair<string, object>>(KeyValuePair<string, object>, IEqualityComparer<KeyValuePair<string, object>>) T
GetPrevious<KeyValuePair<string, object>>(KeyValuePair<string, object>) T
GetRaw(string) object
Gets the raw value for the specified key. This method will not materialize IMetadataValue values the way other get methods will. A System.Collections.Generic.KeyNotFoundException will be thrown for missing keys.
GetRawEnumerable() IEnumerable<KeyValuePair<string, object>>
Gets an enumerable that enumerates raw key-value pairs (I.e., the values have not been expanded similar to TryGetRaw(string, object)).
GetString(string, Func<string, string>, string) string
Formats a string value if it exists in the metadata, otherwise returns a default value.
GetString(string, string) string
Gets the value for the specified key converted to a string. This method never throws an exception. It will return the specified default value if the key is not found.
GroupByMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, TElement>, IEqualityComparer<TKey>) IEnumerable<IGrouping<TKey, TElement>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys. The keys are compared by using a comparer and each group's elements are projected by using a specified function.
GroupByMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, TElement>) IEnumerable<IGrouping<TKey, TElement>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys and projects the elements for each group by using a specified function.
GroupByMany<KeyValuePair<string, object>, TKey>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, IEqualityComparer<TKey>) IEnumerable<IGrouping<TKey, TSource>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys and compares the keys by using a specified comparer.
GroupByMany<KeyValuePair<string, object>, TKey>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>) IEnumerable<IGrouping<TKey, TSource>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys.
GroupByManyToMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, IEnumerable<TElement>>, IEqualityComparer<TKey>) IEnumerable<IGrouping<TKey, TElement>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys. The keys are compared by using a comparer and each group's elements are projected by using a specified function that returns a sequence of elements.
GroupByManyToMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, IEnumerable<TElement>>) IEnumerable<IGrouping<TKey, TElement>>
Groups the elements of a sequence according to a specified key selector function that returns a sequence of keys and projects the elements for each group by using a specified function that returns a sequence of elements.
ParallelForEachAsync<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, Task>, CancellationToken) Task
ParallelSelectAsync<KeyValuePair<string, object>, TResult>(Func<KeyValuePair<string, object>, Task<TResult>>, CancellationToken) Task<IEnumerable<TResult>>
Invokes an async selector in parallel.
ParallelSelectManyAsync<KeyValuePair<string, object>, TResult>(Func<KeyValuePair<string, object>, Task<IEnumerable<TResult>>>, CancellationToken) Task<IEnumerable<TResult>>
Invokes an async selector that returns multiple results in parallel.
ParallelWhereAsync<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, Task<bool>>, CancellationToken) Task<IEnumerable<TSource>>
RemoveAll<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, bool>) int
Removes all items that match a predicate from a collection.
RequireKeys<string, object>(IEnumerable<string>) void
Verifies that a dictionary contains all requires keys. An System.ArgumentException will be thrown if the specified keys are not all present in the dictionary.
RequireKeys<string, object>(string[]) void
Verifies that a dictionary contains all requires keys. An System.ArgumentException will be thrown if the specified keys are not all present in the dictionary.
StartsWith<KeyValuePair<string, object>>(IEnumerable<KeyValuePair<string, object>>, IEqualityComparer<KeyValuePair<string, object>>) bool
Determines whether the items starts with the specified values.
StartsWith<KeyValuePair<string, object>>(IEnumerable<KeyValuePair<string, object>>) bool
Determines whether the items starts with the specified values.
ThrowIfNull<ConvertingDictionary>(string) T
ToDocument<ConvertingDictionary>(IContentProvider) IDocument
ToDocument<ConvertingDictionary>(IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToDocument<ConvertingDictionary>(NormalizedPath, IContentProvider) IDocument
ToDocument<ConvertingDictionary>(NormalizedPath, IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToDocument<ConvertingDictionary>(NormalizedPath, NormalizedPath, IContentProvider) IDocument
ToDocument<ConvertingDictionary>(NormalizedPath, NormalizedPath, IEnumerable<KeyValuePair<string, object>>, IContentProvider) IDocument
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, IEnumerable<KeyValuePair<string, object>>>, Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, IEnumerable<KeyValuePair<string, object>>>, Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToDocuments<KeyValuePair<string, object>>(Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, NormalizedPath>, Func<KeyValuePair<string, object>, IEnumerable<KeyValuePair<string, object>>>, Func<KeyValuePair<string, object>, IContentProvider>) IEnumerable<IDocument>
ToJson(JsonSerializerOptions) string
ToLookupMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, TElement>, IEqualityComparer<TKey>) ILookup<TKey, TElement>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys. The keys are compared by using a comparer and each group's elements are projected by using a specified function.
ToLookupMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, TElement>) ILookup<TKey, TElement>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys and projects the elements for each group by using a specified function.
ToLookupMany<KeyValuePair<string, object>, TKey>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, IEqualityComparer<TKey>) ILookup<TKey, TSource>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys and compares the keys by using a specified comparer.
ToLookupMany<KeyValuePair<string, object>, TKey>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>) ILookup<TKey, TSource>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys.
ToLookupManyToMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, IEnumerable<TElement>>, IEqualityComparer<TKey>) ILookup<TKey, TElement>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys. The keys are compared by using a comparer and each group's elements are projected by using a specified function that returns a sequence of elements.
ToLookupManyToMany<KeyValuePair<string, object>, TKey, TElement>(Func<KeyValuePair<string, object>, IEnumerable<TKey>>, Func<KeyValuePair<string, object>, IEnumerable<TElement>>) ILookup<TKey, TElement>
Creates a lookup from a sequence according to a specified key selector function that returns a sequence of keys and projects the elements for each group by using a specified function that returns a sequence of elements.
ToStringTable<KeyValuePair<string, object>>(string[], Func<KeyValuePair<string, object>, object>[]) string
TryAdd<string, TArg, object>(string, TArg, Func<string, TArg, object>) bool
TryAdd<string, object>(string, Func<string, object>) bool
TryAddRange<string, object>(IEnumerable<KeyValuePair<string, object>>) void
TryGetValue<TValue>(string, TValue) bool
Tries to get the value for the specified key.
WithoutSettings() IMetadata
XAttribute(string, Func<string, string>) XAttribute
XAttribute(string, Func<string, XAttribute>) XAttribute
XAttribute(string, string, Func<string, string>) XAttribute
XAttribute(string, string) XAttribute
Gets an XML attribute for the given metadata key.
XAttribute(string) XAttribute
Gets an XML attribute for the given metadata key. The name of the attribute will be the lower-case key name.
XElement(string, Func<string, object[]>) XElement
XElement(string, Func<string, XElement>) XElement
XElement(string, string, Func<string, object[]>) XElement