CollectionSpy 0.0.4
See the version list below for details.
dotnet add package CollectionSpy --version 0.0.4
NuGet\Install-Package CollectionSpy -Version 0.0.4
<PackageReference Include="CollectionSpy" Version="0.0.4" />
<PackageVersion Include="CollectionSpy" Version="0.0.4" />
<PackageReference Include="CollectionSpy" />
paket add CollectionSpy --version 0.0.4
#r "nuget: CollectionSpy, 0.0.4"
#:package CollectionSpy@0.0.4
#addin nuget:?package=CollectionSpy&version=0.0.4
#tool nuget:?package=CollectionSpy&version=0.0.4
CollectionSpy 🕵️♂️
CollectionSpy allows you to "trap" and debug hidden modifications in your C# lists and dictionaries.
It provides a specialized TrapList<T> and TrapDictionary<TKey, TValue> that act as drop-in replacements for standard collections, enabling you to inject Breakpoints, Stack Traces, or Logs when specific data conditions are met (e.g., "Who added a null ID to this list?").
🚀 Why CollectionSpy?
Debugging legacy code or complex state management can be a nightmare when you don't know who modified a collection.
- Standard
ObservableCollectionis too verbose for debugging (requires event handlers). - Conditional Breakpoints in IDEs are slow and can't be shared with the team.
- AOP Frameworks are overkill for simple debugging tasks.
CollectionSpy solves this with a fluent, declarative API.
📦 Installation
dotnet add package CollectionSpy
⚡ Quick Start
1. Spy on a List
Replace new List<User>() with new TrapList<User>(). It is fully compatible with IList<T>.
using Debugging.Traps;
var users = new TrapList<User>();
// 1. Break execution when a user with null name is added
users.OnAdd()
.When(u => u.Name == null)
.Do(TrapActions.Break());
// 2. Log a warning when a specific ID is removed
users.OnRemove()
.When(u => u.Id == 999)
.Do(TrapActions.Log("WARNING: Admin user 999 was removed!"));
// 3. Print Stack Trace when the list is cleared
users.OnClear()
.Do(TrapActions.DumpStackTrace("List Cleared By"));
2. Spy on a Dictionary
Replace new Dictionary<K, V>() with new TrapDictionary<K, V>().
var config = new TrapDictionary<string, string>();
// Alert if a secure setting is downgraded to HTTP
config.OnUpdate()
.When((key, value) => key == "ApiUrl" && value.StartsWith("http:"))
.Do(TrapActions.Log("SECURITY ALERT: API URL set to insecure HTTP!"));
// Filter by Key only
config.OnAdd()
.WhenKey(k => k.Length > 50)
.Do(() => Console.WriteLine("Performance Warning: Huge key added."));
3. Spy on a HashSet
Replace new HashSet<T>() with new TrapHashSet<T>().
var uniqueTags = new TrapHashSet<string>();
// Detect inefficient code: adding a tag that already exists
uniqueTags.OnAdd()
.When(tag => uniqueTags.Contains(tag))
.Do(TrapActions.Log("Inefficient Code: Tag already exists!"));
// Break when a critical permission is removed
uniqueTags.OnRemove()
.When(tag => tag == "SUPER_ADMIN")
.Do(TrapActions.Break());
### 4. Spy on Queue and Stack
```csharp
var jobQueue = new TrapQueue<string>();
// Debug who added a "Poison Pill" message
jobQueue.OnEnqueue()
.When(msg => msg == "POISON_PILL")
.Do(TrapActions.Break());
// ---
var navStack = new TrapStack<string>();
// Log when the root page is popped
navStack.OnPop()
.When(page => page == "RootPage")
.Do(TrapActions.DumpStackTrace("Root Popped By"));
🛡️ Performance & Production Safety
CollectionSpy is designed to be safe.
Zero-Overhead in Release (Default): The library includes a global switch
TrapManager.Enabled.- DEBUG builds: Enabled by default.
- RELEASE builds: Disabled by default. When disabled, the interception logic returns immediately (fast-fail), imposing negligible performance overhead.
Global Toggle: You can manually control it in your startup logic:
// Force enable in production for emergency diagnostics TrapManager.Enabled = true;Thread Safety: Trap configuration is thread-safe. Execution logic snapshots rules to prevent concurrency issues during enumeration.
📝 License
MIT License. See LICENSE for details.
Maintained by angleyanalbedo
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.