< 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_18869653307
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
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.Engine.Exceptions;
 2using System.Text.Json.Serialization;
 3
 4namespace pva.SuperV.Engine.FieldFormatters
 5{
 6    /// <summary>
 7    /// Base class for <see cref="Field{T}"/> formatting. If adding new formatters, they need to be added as JsonDerived
 8    /// </summary>
 9    [JsonDerivedType(typeof(EnumFormatter), typeDiscriminator: "Enum")]
 10    public abstract class FieldFormatter
 11    {
 23012        private readonly string _name = String.Empty;
 13
 14        public string Name
 15        {
 55516            get => _name;
 17            init
 23018            {
 23019                IdentifierValidation.ValidateIdentifier("field value formatter", value);
 22820                _name = value;
 22821            }
 22        }
 23
 24        /// <summary>
 25        /// Gets or sets the allowed types.
 26        /// </summary>
 27        /// <value>
 28        /// The allowed types.
 29        /// </value>
 30        [JsonIgnore]
 53231        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>
 22738        protected FieldFormatter(string name, HashSet<Type> allowedTypes)
 22739        {
 22740            Name = name;
 22541            AllowedTypes = allowedTypes;
 22542        }
 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)
 29159        {
 29160            if (!AllowedTypes.Contains(fieldType))
 161            {
 162                throw new InvalidTypeForFormatterException(fieldType, Name!);
 63            }
 29064        }
 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}