Class ChecksumBuilderDecoratorExtensions
Extension methods for the ChecksumBuilder class hidden behind the IDecorator<T> interface.
public static class ChecksumBuilderDecoratorExtensions
- Inheritance
-
ChecksumBuilderDecoratorExtensions
Examples
The following example demonstrates how to use ChecksumBuilderDecoratorExtensions to combine typed values with a ChecksumBuilder through the IDecorator<T> interface.
using System;
using Cuemon;
using Cuemon.Data.Integrity;
using Cuemon.Security;
namespace MyApp.Examples;
public class Example
{
public void Run()
{
// Create a ChecksumBuilder wrapped in a Decorator
var builder = new ChecksumBuilder(() => HashFactory.CreateFnv128());
var decorator = Decorator.Enclose(builder);
// Combine various typed values using the decorator extensions
decorator.CombineWith(42); // int
decorator.CombineWith(3.14); // double
decorator.CombineWith("tag"); // string
Console.WriteLine($"Combined checksum: {builder}");
// The extensions return the inner builder for chaining
var combined = decorator.CombineWith(12345L); // long
Console.WriteLine($"Returned type: {combined.GetType().Name}");
// Extension methods also work with short, float, ushort, uint, ulong
var shortDecorator = Decorator.Enclose(new ChecksumBuilder(() => HashFactory.CreateFnv32()));
shortDecorator.CombineWith((short)100);
shortDecorator.CombineWith(3.14f);
shortDecorator.CombineWith(42u);
Console.WriteLine($"Short builder: {shortDecorator.Inner}");
}
}
Methods
CombineWith<T>(IDecorator<T>, byte[])
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, byte[] additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumbyte[]A byte[] containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, double)
Combines the additionalChecksum to the representation of the enclosed ChecksumBuilder of the decorator.
public static T CombineWith<T>(this IDecorator<T> decorator, double additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumdoubleA double value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, short)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, short additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumshortA short value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, int)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, int additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumintA int value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, long)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, long additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumlongA long value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, float)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, float additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumfloatA float value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, string)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, string additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumstringA string containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, ushort)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, ushort additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumushortA ushort value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, uint)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, uint additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumuintA uint value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.
CombineWith<T>(IDecorator<T>, ulong)
Combines the additionalChecksum to the representation of this instance.
public static T CombineWith<T>(this IDecorator<T> decorator, ulong additionalChecksum) where T : ChecksumBuilder
Parameters
decoratorIDecorator<T>The IDecorator<T> to extend.
additionalChecksumulongA ulong value containing a checksum of the additional data the enclosed ChecksumBuilder of the
decoratormust represent.
Returns
- T
An updated instance of the enclosed ChecksumBuilder of the
decorator.
Type Parameters
TThe type of the ChecksumBuilder.
Exceptions
- ArgumentNullException
decoratorcannot be null.