Newer
Older
ClosedXML / ClosedXML / Utils / OpenXmlHelper.cs
@Francois Botha Francois Botha on 12 Mar 2018 478 bytes Fix converter for possible null values.
using DocumentFormat.OpenXml;

namespace ClosedXML.Utils
{
    internal static class OpenXmlHelper
    {
        public static BooleanValue GetBooleanValue(bool value, bool defaultValue)
        {
            return value == defaultValue ? null : new BooleanValue(value);
        }

        public static bool GetBooleanValueAsBool(BooleanValue value, bool defaultValue)
        {
            return (value?.HasValue ?? false) ? value.Value : defaultValue;
        }
    }
}