Class SearchAttributeCollection
- Namespace
- Temporalio.Common
- Assembly
- Temporalio.dll
Read-only collection of typed search attributes. Use a SearchAttributeCollection.Builder to create this collection manually or UpsertTypedSearchAttributes(params SearchAttributeUpdate[]) to update from inside a workflow.
public class SearchAttributeCollection : IReadOnlyCollection<SearchAttributeKey>, IEnumerable<SearchAttributeKey>, IEnumerable
- Inheritance
-
SearchAttributeCollection
- Implements
- Inherited Members
Remarks
When used inside a workflow, this collection is read-only from a usage perspective but can be mutated during workflow run so it is not strictly immutable. From a client perspective, this collection is immutable.
Fields
Empty
An empty search attribute collection.
public static readonly SearchAttributeCollection Empty
Field Value
Properties
Count
Gets the number of search attributes.
public int Count { get; }
Property Value
UntypedValues
Gets a view of the untyped search attribute values.
public IReadOnlyDictionary<SearchAttributeKey, object> UntypedValues { get; }
Property Value
Methods
ContainsKey(string)
Check whether the key name exists.
public bool ContainsKey(string key)
Parameters
key
stringName to check for.
Returns
- bool
Whether key name exists.
ContainsKey<T>(SearchAttributeKey<T>)
Check whether the key name + key type is present.
public bool ContainsKey<T>(SearchAttributeKey<T> key) where T : notnull
Parameters
key
SearchAttributeKey<T>Key to check for.
Returns
- bool
False if the key name + key type are not present, true otherwise.
Type Parameters
T
Key type.
Remarks
It is possible for this to be false but ContainsKey(string) to be true if the key type is different than what is passed here.
FromProto(SearchAttributes)
Convert a protobuf search attribute collection to this collection.
public static SearchAttributeCollection FromProto(SearchAttributes searchAttributes)
Parameters
searchAttributes
SearchAttributesProto search attributes.
Returns
- SearchAttributeCollection
Search attribute collection.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<SearchAttributeKey> GetEnumerator()
Returns
- IEnumerator<SearchAttributeKey>
An enumerator that can be used to iterate through the collection.
Get<T>(SearchAttributeKey<T>)
Get a search attribute if the key name exists and is the right type.
public T Get<T>(SearchAttributeKey<T> key) where T : notnull
Parameters
key
SearchAttributeKey<T>Key to find value for.
Returns
- T
Value.
Type Parameters
T
Key type.
Exceptions
- KeyNotFoundException
If the key name + key type not found.
- InvalidCastException
On older servers and/or older workflows from other SDKs that used things like lists for types, the cast can fail and UntypedValues may have to be used directly.
ToProto()
Convert this collection to protobuf search attributes.
public SearchAttributes ToProto()
Returns
- SearchAttributes
Protobuf search attributes.
TryGetValue<T>(SearchAttributeKey<T>, out T)
Try to get the search attribute if the key exists and is the right type.
public bool TryGetValue<T>(SearchAttributeKey<T> key, out T value) where T : notnull
Parameters
key
SearchAttributeKey<T>Key to find value for.
value
TValue to set.
Returns
- bool
False if the key name + key type is not found, true if found and set.
Type Parameters
T
Key type.
Remarks
On older servers and/or older workflows from other SDKs that used things like lists for types, the cast can fail and UntypedValues may have to be used directly.