Use Collections Safely
Choose Sharp Runtime collection components and preserve iterator/versioning semantics.
Choose the family first
| Need | Component |
|---|---|
| Synchronous lists, dictionaries, sets, queues | Collections.Core |
| Blocking producer/consumer queue | Collections.Blocking |
| Async enumeration contracts | Collections.Async |
| Observable/object-model collections | Collections.ObjectModel |
Select it
set(SHARP_RUNTIME_COMPONENTS Collections.Core)
target_link_libraries(app PRIVATE SharpRuntime::Collections.Core)
Native rules still apply
- Mutation invalidates version-sensitive enumerators; do not keep them across changes.
- Container element ownership follows the chosen C++ value/pointer type.
- Concurrent collections do not make the objects stored inside them thread-safe.
- Floating keys need an intentional comparer policy, particularly for NaN and signed zero.
Avoid transliteration by type name alone
A C# collection of managed objects and a C++ collection of values have different copy, identity and lifetime behavior. Decide the element model before selecting the container.