Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

Implemented PrintContents extension method for the ILinks<TLinkAddress> interface to provide a configurable way to output the contents of a links database.

Key Features

  • Configurable output handler: Uses Action<string> messageHandler parameter instead of hardcoded Console.WriteLine
  • Empty database handling: Displays "Database is empty." when no links exist
  • Proper formatting: Each link displayed as [linkIndex]: source -> target with zero-padding alignment
  • Generic type support: Works with any TLinkAddress type that implements required constraints

Implementation Details

  • Added to ILinksExtensions.cs following existing patterns in the codebase
  • Based on the reference implementation from MasterServer.cs#L30-L49
  • Uses proper XML documentation following project conventions
  • Includes [MethodImpl(MethodImplOptions.AggressiveInlining)] attribute for performance

Example Usage

// Output to console
links.PrintContents(Console.WriteLine);

// Capture to list
var messages = new List<string>();
links.PrintContents(messages.Add);

// Custom handler
links.PrintContents(msg => logger.Info(msg));

Testing

  • ✅ All existing tests pass (20/20)
  • ✅ Tested with empty database scenario
  • ✅ Tested with populated database
  • ✅ Verified proper formatting and alignment
  • ✅ Added experimental test project for validation

Addresses Issue Requirements

Technical Notes

  • Method signature: public static void PrintContents<TLinkAddress>(this ILinks<TLinkAddress> links, Action<string> messageHandler)
  • Constraints: where TLinkAddress : IUnsignedNumber<TLinkAddress>, IComparisonOperators<TLinkAddress, TLinkAddress, bool>
  • Iterates through all links using links.All() method
  • Handles null links gracefully with null checks

Fixes #150

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #150
@konard konard self-assigned this Sep 14, 2025
- Implemented PrintContents extension method with configurable Action<string> output handler
- Handles empty database case with appropriate message
- Formats each link with proper alignment and zero-padding
- Uses format: [linkIndex]: source -> target
- Based on reference implementation from MasterServer.cs
- Addresses issue #150 requirement for common interface instead of Console.WriteLine

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add PrintContents/Output extension method for ILinks interface Add PrintContents extension method for ILinks interface Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PrintContents/Output extension method for ILinks interface

2 participants