コード例 #1
0
        public void Icon_Should_Exist_And_Be_Valid_SVG_Path(string value)
        {
            // Act #1
            var path = _iconProvider.GetIconPath($"mdi-{value}");

            // Assert #1
            path.Should().NotBeNullOrEmpty();

            // Act #2
            var skiaPath = SKPath.ParseSvgPathData(path);

            // Assert #2
            skiaPath.Should().NotBeNull();
            skiaPath.Bounds.IsEmpty.Should().BeFalse();
        }
コード例 #2
0
        /// <summary>
        /// Gets the SVG path of the icon associated with the specified value using the registered icon providers.
        /// </summary>
        /// <param name="value">The value specifying the icon to return it's path from.</param>
        /// <returns>If <paramref name="value"/> is not <c>null</c> or empty the path of the icon; otherwise <c>string.Empty</c>.</returns>
        /// <exception cref="KeyNotFoundException">No provider with prefix matching <paramref name="value"/> found.</exception>
        /// <exception cref="KeyNotFoundException">No icon associated
        /// with the specified <paramref name="value"/> found.</exception>
        public static string GetIconPath(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            IIconProvider provider = _iconProvidersByPrefix
                                     .Select(prefixProviderPair => prefixProviderPair.Value)
                                     .FirstOrDefault(provider => value.StartsWith(provider.Prefix, StringComparison.OrdinalIgnoreCase));

            if (provider is null)
            {
                throw new KeyNotFoundException($"No provider with prefix matching \"{value}\" found.");
            }
            else
            {
                return(provider.GetIconPath(value));
            }
        }