Search
Write a publication
Pull to refresh
0
0
Send message

У каждого шаблона, естественно, своя область применения.

exactly… Во-первых, тут достаточно struct, во вторых, решение с вводом дополнительных классов "Success" и "Failure" мне кажется неоправданным

В случае с асинхронными методами мне приглянулся класс (вернее — struct) "CondirionalValue" от Майкрософт:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.servicefabric.data.conditionalvalue-1?view=azure-dotnet


Я его перенял и немного переименовал:


public struct ConditionalObject<TValue>
    {
        /// <summary>
        /// Initializes a new instance of the <cref name="ConditionalObject{TValue}" /> class with the given value.
        /// </summary>
        /// <param name="hasValue">Indicates whether the value is valid.</param>
        /// <param name="value">The value.</param>
        public ConditionalObject(bool hasValue, TValue value)
        {
            HasValue = hasValue;
            Value = value;
        }

        /// <summary>
        /// Gets a value indicating whether the current <cref name="ConditionalObject{TValue}" /> object has a valid value of its underlying type.
        /// </summary>
        /// <returns><languageKeyword>true</languageKeyword>: Value is valid, <languageKeyword>false</languageKeyword> otherwise.</returns>
        public bool HasValue { get; }

        /// <summary>
        /// Gets the value of the current <cref name="ConditionalObject{TValue}" /> object if it has been assigned a valid underlying value.
        /// </summary>
        /// <returns>The value of the object. If HasValue is <languageKeyword>false</languageKeyword>, returns the default value for type of the TValue parameter.</returns>
        public TValue Value { get; }
    }

О паттерне "MayBe" я впервые узнал от Марка Зимана: Ссылка: The Maybe functor из его курса Encapsulation and SOLID

Если важна скорость, то рекомендую https://www.spreadsheetgear.com/ У нас есть несколько серверных решений на основе этой библиотеки. Измерения показали, что SpreadsheetGear работает намного быстрее, чем EPPlus

Information

Rating
Does not participate
Registered
Activity