Coree.NETStandard
  • API
Show / Hide Table of Contents
  • Coree.NETStandard.Abstractions.DependencySingleton
    • DependencySingleton<T>
    • IDependencySingleton
  • Coree.NETStandard.Abstractions.FluentBase
    • FluentBase
    • IFluentBase
  • Coree.NETStandard.Abstractions.InitializationService
    • InitializationDependentServices
    • InitializationService
  • Coree.NETStandard.Abstractions.ServiceFactory
    • ServiceFactory<T>
  • Coree.NETStandard.Abstractions.ServiceFactoryEx
    • ServiceFactoryEx<T>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y, Z>
    • ServiceFactoryEx<T, K>
    • ServiceFactoryEx<T, K, R>
    • ServiceFactoryEx<T, K, R, S>
    • ServiceFactoryEx<T, K, R, S, U>
    • ServiceFactoryEx<T, K, R, S, U, V>
    • ServiceFactoryEx<T, K, R, S, U, V, W>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X>
    • ServiceFactoryEx<T, K, R, S, U, V, W, X, Y>
  • Coree.NETStandard.Classes.AsyncEventCollection
    • AsyncEventCollection<T>
    • AsyncEventCollection<T>.CustomEventDelegate
  • Coree.NETStandard.Classes.CommonDistinguishedNameBuilder
    • CommonDistinguishedNameBuilder
    • DistinguishedName
  • Coree.NETStandard.Classes.Criteria
    • CriteriaComparisonMethod
    • CriteriaEnumerableExtensions
    • CriteriaExpressionBuilder
    • CriteriaItem<TValue>
    • CriteriaItems
    • CriteriaOperator
    • CriteriaQueryableExtensions
  • Coree.NETStandard.Classes.HttpRequestService
    • ContentComposer
    • HttpRequestHeadersExtensions
    • HttpRequestService
    • HttpRequestServiceHandler
    • HttpRequestServiceUriExtensions
    • ServiceCollectionExtensions
    • TransactionRecord
  • Coree.NETStandard.Classes.Scheduler
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
  • Coree.NETStandard.Classes.ThreadSafeCollection
    • ThreadSafeCollection<T>
  • Coree.NETStandard.Classes.ThreadSafeValue
    • ThreadSafeValue<T>
  • Coree.NETStandard.Classes.TimeOfDay
    • TimeOfDay
  • Coree.NETStandard.Extensions.Collections.Enumerable
    • CollectionsEnumerableExtensions
  • Coree.NETStandard.Extensions.Collections.List
    • CollectionsListExtensions
  • Coree.NETStandard.Extensions.Conversions.ByteArray
    • ConversionsByteArrayExtensions
  • Coree.NETStandard.Extensions.Conversions.HostApplicationBuilder
    • ConversionsHostApplicationBuilderExtensions
  • Coree.NETStandard.Extensions.Conversions.String
    • ConversionsStringExtensions
    • Encodings
  • Coree.NETStandard.Extensions.Conversions.Stringbuilder
    • ConversionsStringbuilderExtension
  • Coree.NETStandard.Extensions.Enums
    • EnumExtensions
  • Coree.NETStandard.Extensions.Http.HttpHeader
    • HttpHeadersExtensions
  • Coree.NETStandard.Extensions.Primitives.Bool
    • PrimitivesBoolExtensions
  • Coree.NETStandard.Extensions.Reflection.ServiceProvider
    • ReflectionServiceProviderExtensions
  • Coree.NETStandard.Extensions.ServiceCollection
    • ServiceCollectionExtensions
  • Coree.NETStandard.Extensions.Threading.CancellationToken
    • ThreadingCancellationTokenExtensions
  • Coree.NETStandard.Extensions.Utilities
    • DateTimeExtensions
  • Coree.NETStandard.Extensions.Validations.String
    • ValidationsStringExtensions
  • Coree.NETStandard.HostedServicesCollection
    • HostedServicesCollectionConfig<T>
    • IHostedServicesCollectionConfig<T>
    • ServiceCollectionExtensions
    • ServiceProviderExtensions
  • Coree.NETStandard.Serilog
    • ConditionalLevelSink
    • CustomTheme
    • LoggerSinkConfigurationExtensions
    • OutputTemplates
    • ServiceCollectionExtensions
    • SourceContextShortEnricher
  • Coree.NETStandard.Services.DebugManagement
    • DebugService
    • IDebugService
  • Coree.NETStandard.Services.DirectoryOperationsManagement
    • DirectoryOperationsService
    • IDirectoryOperationsService
  • Coree.NETStandard.Services.FileManagement
    • FileService
    • IFileService
  • Coree.NETStandard.Services.FileOperationsManagement
    • FileOperationsService
    • FileOperationsService.FileSystemEntry
    • FileOperationsService.FileSystemInformation
    • FileOperationsService.VerifiedCopyStatus
    • IFileOperationsService
  • Coree.NETStandard.Services.HashManagement
    • HashService
    • IHashService
  • Coree.NETStandard.Services.NetworkManagement
    • INetworkService
    • NetworkService
    • NetworkService.IpAdressInformation
    • NetworkService.NetworkInterfaceDetail
  • Coree.NETStandard.Services.ProcessManagement
    • IProcessService
    • ProcessRunExitCodeState
    • ProcessRunResult
    • ProcessService
  • Coree.NETStandard.Services.RuntimeInsightsManagement
    • IRuntimeInsightsService
    • RuntimeInsightsService
  • Coree.NETStandard.SpectreConsole
    • CommandAppExtensions
    • HostBuilderExtensions
    • ServiceCollectionExtensions
    • SpectreConsoleHostedService
    • SpectreConsoleHostedService.ExitCode
    • SpectreConsoleTypeRegistrar
    • SpectreConsoleTypeResolver
  • Coree.NETStandard.UnderConstruction
    • DbContextExtensions
    • HttpClientStatic
    • HttpClientStatic.HttpClientResponse
    • HttpClientStatic.XRate
    • HttpClientStatic.XRateGroup
    • HttpClientStatic.XRateItem
    • IScheduleProvider
    • IntervalScheduleProvider
    • LimitedHistory<T>
    • ScheduleCombiner
    • Scheduler
    • Scheduler.TickerEventArgs
    • Scheduler.TickerEventDelegate
    • Scheduler2
    • Scheduler2.TickerEventArgs
    • Scheduler2.TickerEventDelegate
    • Scheduler3
    • Scheduler3.TickerEventArgs
    • Scheduler3.TickerEventDelegate
    • SqlliteMemoryContext
    • SqlliteMemoryContext.UserDataDto
    • TimedEntry<T>
    • Timing
    • Timing.Ticker
    • Timing.Ticker.TickerEventArgs
    • Timing.TickerSync
    • WeekDayAtScheduleProvider
  • Coree.NETStandard.Utilities
    • EventSubscription
    • MainContext

Class FluentBase

Acts as an abstract foundation for structured error handling in classes using a fluent interface pattern. Offers mechanisms to either immediately throw or accumulate exceptions, alongside managing continuation after validation errors.

Inheritance
object
FluentBase
Implements
IFluentBase
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Coree.NETStandard.Abstractions.FluentBase
Assembly: Coree.NETStandard.dll
Syntax
public abstract class FluentBase : IFluentBase
Remarks

Implements the IFluentBase interface to supply default methods and properties, facilitating the easy integration of a uniform error handling strategy across derived classes. This base class is designed to empower your fluent interfaces with sophisticated error handling capabilities, allowing for the graceful accumulation of errors for later analysis or immediate failure upon error detection to prevent further processing under invalid conditions.

Example usage in a simplified Product class inheriting from FluentBase and an extension method to adjust its price:

// Inheriting FluentBase in a Product class
public class Product : FluentBase
{
    public string Name { get; set; }
    public decimal Price { get; set; }
}

// Extension method for the Product class to adjust its price public static class ProductExtensions { public static Product AdjustPrice(this Product product, decimal adjustment) { // Early exit if the product is invalid and continuation on validation error is not enabled if (!product.IsValid && !product.ContinueOnValidationError) return product;

    try
    {
        // Attempt to adjust the product's price
        var newPrice = product.Price + adjustment;
        if (newPrice < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(adjustment), "Adjustment results in a negative price.");
        }
        product.Price = newPrice;
    }
    catch (Exception ex)
    {
        // Add a validation error in case of an exception
        product.AddValidationError($"Error adjusting price by {adjustment}: {ex.Message}", ex);
    }

    return product;
}

}

This exemplifies how Product, by inheriting FluentBase, utilizes built-in error handling for a price adjustment operation, demonstrating the class's utility in creating fluent interfaces with integrated error management.

Properties

| Edit this page View Source

ContinueOnValidationError

Indicates whether operations should continue after a validation error has occurred, based on the current configuration.

Declaration
public bool ContinueOnValidationError { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsValid

Indicates whether the current object is in a valid state, based on the absence of validation errors.

Declaration
public bool IsValid { get; }
Property Value
Type Description
bool
| Edit this page View Source

ThrowOnError

Gets a value indicating whether exceptions are thrown immediately upon encountering a validation error. This property is set through EnableThrowOnError() and DisableThrowOnError(bool) methods.

Declaration
public bool ThrowOnError { get; }
Property Value
Type Description
bool
| Edit this page View Source

ValidationErrors

Gets a collection of exceptions that have been accumulated during operation executions.

Declaration
public List<Exception> ValidationErrors { get; }
Property Value
Type Description
List<Exception>

Methods

| Edit this page View Source

AddValidationError(string, Exception)

Adds a specified validation error to the collection, throwing an exception if configured to do so.

Declaration
public void AddValidationError(string message, Exception innerException)
Parameters
Type Name Description
string message

The error message.

Exception innerException

The exception that represents the error.

| Edit this page View Source

DisableThrowOnError(bool)

Configures the class to accumulate validation errors without throwing exceptions immediately, with an option to continue operations after encountering a validation error.

Declaration
public IFluentBase DisableThrowOnError(bool continueOnValidationError = false)
Parameters
Type Name Description
bool continueOnValidationError

Indicates whether to continue operations after a validation error has occurred.

Returns
Type Description
IFluentBase

The current instance of FluentBase, enabling fluent configuration.

| Edit this page View Source

EnableThrowOnError()

Configures the class to throw exceptions immediately upon encountering a validation error.

Declaration
public IFluentBase EnableThrowOnError()
Returns
Type Description
IFluentBase

The current instance of FluentBase, enabling fluent configuration.

Implements

IFluentBase
  • Edit this page
  • View Source
In this article
Back to top