base library

Base cloning implementation and interface for custom cloning strategies.

This library provides the foundational types for building cloning implementations:

Difference from core.dart:

  • core.dart exports the high-level Cloner API for everyday use
  • base.dart exports lower-level primitives for advanced customization

When to use base.dart:

  • Implementing a custom ICloning strategy (e.g., logging, metrics, special type handling)
  • Directly instantiating BaseCloner with specific options using builder pattern
  • Building frameworks or libraries that extend cloning behavior

Example: Custom cloning implementation

import 'package:cloner/base.dart';
import 'package:cloner/core.dart';

class LoggingCloner implements ICloning {
  final ICloning _delegate;

  LoggingCloner([ICloning? delegate]) : _delegate = delegate ?? const BaseCloner(true);

  @override
  dynamic cloneValue(dynamic source) {
    print('Cloning: ${source.runtimeType}');
    return _delegate.cloneValue(source);
  }

  // ... implement other ICloning methods
}

// Replace global cloner
Cloner.builder = LoggingCloner();

Classes

AdaptiveCloner
Dispatches cloning operations to appropriate delegates based on configuration.
AdaptiveClonerBuilder
Builder for AdaptiveCloner, allowing configuration of delegates and mode.
BaseCloner
Performs element/value-wise cloning for built-in collections and delegates to ICloneable implementations for custom types.
BaseClonerBuilder
Builder for BaseCloner
CountedCloner
Extended with enforced recursion and size limits BaseCloner. The lightest way to prevent StackOverflow for circle references.
CountedClonerBuilder
Builder for CountedCloner
DICloning
HashedCloner
Cloner with circular reference detection.
HashedClonerBuilder
Builder for HashedCloner
IClonerBuilding
Interface for types that can construct an ICloning instance (builder pattern).
ICloning
Interface for types that perform cloning operations (i.e., cloners).

Mixins

MClonerLogging
A mixin that adds logging capabilities to cloning operations.