< Summary

Information
Class: NtpServiceLibrary.SettingsValue<T>
Assembly: NtpServiceLibrary
File(s): D:\a\ntp-service\ntp-service\NtpServiceLibrary\Settings.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 96
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
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()100%11100%
op_Explicit(...)100%11100%
Set(...)100%11100%
ToString()100%44100%

File(s)

D:\a\ntp-service\ntp-service\NtpServiceLibrary\Settings.cs

#LineLine coverage
 1namespace NtpServiceLibrary
 2{
 3    /// <summary>
 4    /// Represents a strongly-typed setting value with change tracking and source information.
 5    /// </summary>
 6    /// <typeparam name="T">Type of the setting value.</typeparam>
 7    public class SettingsValue<T>
 8    {
 9        private T _value;
 4610        private string _source = "";
 4611        private bool _changed = false;
 12
 13        /// <summary>
 14        /// Initializes a new instance of the <see cref="SettingsValue{T}"/> class with a default value.
 15        /// </summary>
 16        /// <param name="defaultValue">The default value.</param>
 4617        public SettingsValue(T defaultValue)
 4618        {
 4619            _value = defaultValue;
 4620        }
 21
 22        /// <summary>
 23        /// Gets the current value.
 24        /// </summary>
 25        public T Get()
 3826        {
 3827            return _value;
 3828        }
 29
 30        public static explicit operator T(SettingsValue<T> value)
 1231        {
 1232            return value.Get();
 1233        }
 34
 35        /// <summary>
 36        /// Sets the value and marks it as changed.
 37        /// </summary>
 38        /// <param name="value">The new value.</param>
 39        /// <param name="source">Optional source description.</param>
 40        public void Set(T value, string source = "")
 1041        {
 1042            _value = value;
 1043            _source = source;
 1044            _changed = true;
 1045        }
 46
 47        /// <summary>
 48        /// Returns a string representation of the value, including change and source info.
 49        /// </summary>
 50        public override string ToString()
 3251        {
 3252            return string.Format("{0}{1}{2}",
 3253                _value.ToString(),
 3254                _changed ? "" : " (default)",
 3255                _source != "" ? string.Format(" <{0}>", _source) : ""
 3256            );
 3257        }
 58    }
 59
 60    /// <summary>
 61    /// Holds all configurable NTP service settings.
 62    /// </summary>
 63    public class Settings
 64    {
 65        internal const string DefaultNTPServer = "pool.ntp.org";
 66        internal const int DefaultNTPPort = 123;
 67        internal const int DefaultNTPPollIntervalHours = 6;
 68
 69        /// <summary>
 70        /// NTP server address.
 71        /// </summary>
 72        public SettingsValue<string> NTPServer = new SettingsValue<string>(DefaultNTPServer);
 73
 74        /// <summary>
 75        /// NTP server port.
 76        /// </summary>
 77        public SettingsValue<int> NTPPort = new SettingsValue<int>(DefaultNTPPort);
 78
 79        /// <summary>
 80        /// Poll interval in hours.
 81        /// </summary>
 82        public SettingsValue<int> NTPPollIntervalHours = new SettingsValue<int>(DefaultNTPPollIntervalHours);
 83
 84        /// <summary>
 85        /// Returns a string representation of all settings.
 86        /// </summary>
 87        public override string ToString()
 88        {
 89            return string.Format("Server: {0}\nPort: {1}\nPollIntervalHours: {2}\n",
 90                NTPServer.ToString(),
 91                NTPPort.ToString(),
 92                NTPPollIntervalHours.ToString()
 93            );
 94        }
 95    }
 96}