Table of Contents

Class DoubleDecoratorExtensions

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Extension methods for the double struct hidden behind the IDecorator<T> interface.

public static class DoubleDecoratorExtensions
Inheritance
DoubleDecoratorExtensions

Examples

DoubleDecoratorExtensions provides extension methods on Decorator.Enclose for converting double values into TimeSpan instances using the ToTimeSpan method with a specified TimeUnit. This example creates four double values representing 1.5 days, 90 minutes, 5000 milliseconds, and 2.5 hours, each wrapped with Decorator.Enclose and passed to ToTimeSpan with the matching time unit. Key setup includes choosing the correct TimeUnit enum value for each conversion. Console output shows 1.12:00:00 for 1.5 days, 01:30:00 for 90 minutes, 00:00:05 for 5000 milliseconds, and 02:30:00 for 2.5 hours.

using System;
using Cuemon;

namespace MyApp.Numeric
{
    public class DoubleDecoratorExtensionsExample
    {
        public void Demonstrate()
        {
            // Convert 1.5 days to a TimeSpan
            double days = 1.5;
            TimeSpan duration = Decorator.Enclose(days).ToTimeSpan(TimeUnit.Days);
            Console.WriteLine(duration); // Output: 1.12:00:00

            // Convert 90 minutes to a TimeSpan
            double minutes = 90;
            TimeSpan meeting = Decorator.Enclose(minutes).ToTimeSpan(TimeUnit.Minutes);
            Console.WriteLine(meeting); // Output: 01:30:00

            // Convert 5000 milliseconds to a TimeSpan
            double ms = 5000;
            TimeSpan interval = Decorator.Enclose(ms).ToTimeSpan(TimeUnit.Milliseconds);
            Console.WriteLine(interval); // Output: 00:00:05

            // Convert 2.5 hours to a TimeSpan
            double hours = 2.5;
            TimeSpan task = Decorator.Enclose(hours).ToTimeSpan(TimeUnit.Hours);
            Console.WriteLine(task); // Output: 02:30:00

}}
}

Methods

ToTimeSpan(IDecorator<double>, TimeUnit)

Converts the enclosed double of the decorator to its equivalent TimeSpan representation.

public static TimeSpan ToTimeSpan(this IDecorator<double> decorator, TimeUnit unitOfTime)

Parameters

decorator IDecorator<double>

The IDecorator<T> to extend.

unitOfTime TimeUnit

One of the enumeration values that specifies the outcome of the conversion.

Returns

TimeSpan

A TimeSpan that corresponds to the enclosed double of the decorator and unitOfTime.

Exceptions

ArgumentNullException

decorator cannot be null.

OverflowException

The enclosed double of the decorator paired with unitOfTime is outside its valid range.

InvalidEnumArgumentException

unitOfTime was outside its valid range.

See Also