< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.EncodingConverter
Assembly: CoreWCF.ConfigurationManager
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/EncodingConverter.cs
Line coverage
36%
Covered lines: 7
Uncovered lines: 12
Coverable lines: 19
Total lines: 66
Line coverage: 36.8%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CanConvertFrom(...)0%220%
CanConvertTo(...)0%220%
ConvertFrom(...)66.66%6677.77%
ConvertTo(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/EncodingConverter.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.ComponentModel;
 6using System.ComponentModel.Design.Serialization;
 7using System.Text;
 8
 9namespace CoreWCF.Configuration
 10{
 11    internal class EncodingConverter : TypeConverter
 12    {
 13        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
 14        {
 015            if (typeof(string) == sourceType)
 16            {
 017                return true;
 18            }
 019            return base.CanConvertFrom(context, sourceType);
 20        }
 21
 22        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
 23        {
 024            if (typeof(InstanceDescriptor) == destinationType)
 25            {
 026                return true;
 27            }
 028            return base.CanConvertTo(context, destinationType);
 29        }
 30
 31        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, obj
 32        {
 1033            if (value is string)
 34            {
 1035                string encoding = (string)value;
 36
 37                Encoding retval;
 1038                if (String.Compare(encoding, "utf-8", StringComparison.OrdinalIgnoreCase) == 0)
 39                {
 40                    // special case for utf-8 to match with what we do in the default text encoding
 741                    retval = Encoding.UTF8;
 42                }
 43                else
 44                {
 345                    retval = Encoding.GetEncoding(encoding);
 46                }
 1047                if (retval == null)
 48                {
 049                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.ConfigInvalidEncoding
 50                }
 1051                return retval;
 52            }
 053            return base.ConvertFrom(context, culture, value);
 54        }
 55
 56        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, objec
 57        {
 058            if (typeof(string) == destinationType && value is Encoding)
 59            {
 060                Encoding encoding = (Encoding)value;
 061                return encoding.HeaderName;
 62            }
 063            return base.ConvertTo(context, culture, value, destinationType);
 64        }
 65    }
 66}