Documentation Coverage Report
Current view: top level - Cqrs.WebApi/Formatters/FormMultipart/Infrastructure/TypeConverters - BooleanConverterEx.cs Hit Total Coverage
Version: 2.2 Artefacts: 2 2 100.0 %
Date: 2018-08-07 15:04:50

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.ComponentModel;
      11             : using System.Globalization;
      12             : 
      13             : namespace Cqrs.WebApi.Formatters.FormMultipart.Infrastructure.TypeConverters
      14             : {
      15             :         /// <summary>
      16             :         /// Provides a <see cref="TypeConverter"/> to convert <see cref="bool"/> objects to and from various other representations
      17             :         /// with support for HTTP specification specific values such as ON or OFF.
      18             :         /// </summary>
      19             :         public class BooleanConverterEx : BooleanConverter
      20           1 :         {
      21             :                 /// <summary>
      22             :                 /// Converts the given <paramref name="value"/> object to a <see cref="bool"/> object.
      23             :                 /// </summary>
      24             :                 /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
      25             :                 /// <param name="culture">A <see cref="CultureInfo"/> that specifies the culture to which to convert.</param>
      26             :                 /// <param name="value">The <see cref="object"/> to convert.</param>
      27             :                 /// <returns>An <see cref="object"/> that represents the converted <paramref name="value"/>.</returns>
      28           1 :                 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
      29             :                 {
      30             :                         if (value != null)
      31             :                         {
      32             :                                 var str = value.ToString();
      33             : 
      34             :                                 if (String.Compare(str, "on", culture, CompareOptions.IgnoreCase) == 0)
      35             :                                         return true;
      36             : 
      37             :                                 if (String.Compare(str, "off", culture, CompareOptions.IgnoreCase) == 0)
      38             :                                         return false;
      39             :                         }
      40             : 
      41             :                         return base.ConvertFrom(context, culture, value);
      42             :                 }
      43             :         }
      44             : }

Generated by: LCOV version 1.12