< Summary - pva.SuperV

Information
Class: pva.SuperV.Engine.FieldFormatters.FieldFormatter
Assembly: pva.SuperV.Engine
File(s): /home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/FieldFormatters/FieldFormatter.cs
Tag: dotnet-ubuntu_22190969454
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 75
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
set_Name(...)100%11100%
get_AllowedTypes()100%11100%
.ctor(...)100%11100%
ValidateAllowedType(...)100%22100%

File(s)

/home/runner/work/pva.SuperV/pva.SuperV/pva.SuperV.Engine/FieldFormatters/FieldFormatter.cs

#LineLine coverage
 1using pva.SuperV.Common;
 2using pva.SuperV.Engine.Exceptions;
 3using System.Text.Json.Serialization;
 4
 5namespace pva.SuperV.Engine.FieldFormatters
 6{
 7    /// <summary>
 8    /// Base class for <see cref="Field{T}"/> formatting. If adding new formatters, they need to be added as JsonDerived
 9    /// </summary>
 10    [JsonDerivedType(typeof(EnumFormatter), typeDiscriminator: "Enum")]
 11    public abstract class FieldFormatter
 12    {
 24313        private readonly string _name = String.Empty;
 14
 15        public string Name
 16        {
 62717            get => _name;
 18            init
 24319            {
 24320                _name = IdentifierValidation.ValidateIdentifier("field value formatter", value);
 24121            }
 22        }
 23
 24        /// <summary>
 25        /// Gets or sets the allowed types.
 26        /// </summary>
 27        /// <value>
 28        /// The allowed types.
 29        /// </value>
 30        [JsonIgnore]
 57131        public HashSet<Type> AllowedTypes { get; init; }
 32
 33        /// <summary>
 34        /// Initializes a new instance of the <see cref="FieldFormatter"/> class.
 35        /// </summary>
 36        /// <param name="name">The name.</param>
 37        /// <param name="allowedTypes">The allowed types.</param>
 24038        protected FieldFormatter(string name, HashSet<Type> allowedTypes)
 24039        {
 24040            Name = name;
 23841            AllowedTypes = allowedTypes;
 23842        }
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="FieldFormatter"/> class.
 46        /// </summary>
 47        /// <param name="allowedTypes">The allowed types.</param>
 348        protected FieldFormatter(HashSet<Type> allowedTypes)
 349        {
 350            AllowedTypes = allowedTypes;
 351        }
 52
 53        /// <summary>
 54        /// Validates that type is part of the allowed types of formatter.
 55        /// </summary>
 56        /// <param name="fieldType">Type of the field.</param>
 57        /// <exception cref="InvalidTypeForFormatterException"></exception>
 58        internal void ValidateAllowedType(Type fieldType)
 31759        {
 31760            if (!AllowedTypes.Contains(fieldType))
 161            {
 162                throw new InvalidTypeForFormatterException(fieldType, Name!);
 63            }
 31664        }
 65
 66        /// <summary>
 67        /// Converts a value to string.
 68        /// </summary>
 69        /// <param name="value">The value.</param>
 70        /// <returns>String representing the value.</returns>
 71        public abstract string? ConvertToString(dynamic? value);
 72
 73        public abstract void ConvertFromString(IField field, string? stringValue, DateTime? timestamp, QualityLevel? qua
 74    }
 75}