< Summary

Information
Class: MyNet.Text.TextTemplatingExtensions
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/TextTemplatingExtensions.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 116
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ResolveTemplate(...)100%210%
ResolveTemplate(...)100%210%
ResolveTemplate(...)100%210%
ResolveTemplate(...)100%210%
ResolveTemplate(...)0%620%
ResolveTemplate(...)0%620%
ResolveTemplate(...)0%620%
ResolveTemplate(...)0%620%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/TextTemplatingExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TextTemplatingExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Globalization;
 10using MyNet.Text.Templating;
 11
 12#pragma warning disable IDE0130 // Namespace does not match folder structure
 13namespace MyNet.Text;
 14#pragma warning restore IDE0130 // Namespace does not match folder structure
 15
 16public static class TextTemplatingExtensions
 17{
 18    extension(TextPipeline pipeline)
 19    {
 20        /// <summary>
 21        /// Resolves the template using the provided transform. Transformations are applied in the provided order.
 22        /// </summary>
 23        /// <param name="transform">The template transform to apply.</param>
 24        /// <returns>The transformed TextPipeline instance.</returns>
 25        public TextPipeline ResolveTemplate(ITemplateTransform transform)
 26        {
 027            ArgumentNullException.ThrowIfNull(transform);
 028            return pipeline.Apply(transform);
 29        }
 30
 31        /// <summary>
 32        /// Resolves the template using the provided options. Transformations are applied in the provided order.
 33        /// </summary>
 34        /// <param name="options">The template options to apply.</param>
 35        /// <returns>The transformed TextPipeline instance.</returns>
 36        public TextPipeline ResolveTemplate(TextTemplateOptions options)
 37        {
 038            ArgumentNullException.ThrowIfNull(options);
 039            return pipeline.Apply(new TemplateTransform(options));
 40        }
 41
 42        /// <summary>
 43        /// Resolves the template using the provided configuration action. Transformations are applied in the provided o
 44        /// </summary>
 45        /// <param name="configure">The configuration action to apply.</param>
 46        /// <returns>The transformed TextPipeline instance.</returns>
 47        public TextPipeline ResolveTemplate(Action<TextTemplateOptionsBuilder> configure)
 48        {
 049            ArgumentNullException.ThrowIfNull(configure);
 050            return pipeline.Apply(TextTemplating.Create(configure));
 51        }
 52
 53        /// <summary>
 54        /// Resolves the template using the provided arguments. Transformations are applied in the provided order.
 55        /// </summary>
 56        /// <param name="arguments">The arguments to apply.</param>
 57        /// <returns>The transformed TextPipeline instance.</returns>
 58        public TextPipeline ResolveTemplate(IEnumerable<KeyValuePair<string, object?>> arguments)
 59        {
 060            ArgumentNullException.ThrowIfNull(arguments);
 061            return pipeline.Apply(TextTemplating.Create(x => x.WithArguments(arguments)));
 62        }
 63    }
 64
 65    extension(string input)
 66    {
 67        /// <summary>
 68        /// Resolves the template using the provided transform. Transformations are applied in the provided order.
 69        /// </summary>
 70        /// <param name="transform">The template transform to apply.</param>
 71        /// <param name="culture">The culture to use for the transformation.</param>
 72        /// <returns>The transformed string.</returns>
 73        public string ResolveTemplate(ITemplateTransform transform, CultureInfo? culture = null)
 74        {
 075            ArgumentNullException.ThrowIfNull(transform);
 076            return transform.Apply(input, culture ?? CultureInfo.CurrentCulture);
 77        }
 78
 79        /// <summary>
 80        /// Resolves the template using the provided options. Transformations are applied in the provided order.
 81        /// </summary>
 82        /// <param name="options">The template options to apply.</param>
 83        /// <param name="culture">The culture to use for the transformation.</param>
 84        /// <returns>The transformed string.</returns>
 85        public string ResolveTemplate(TextTemplateOptions options, CultureInfo? culture = null)
 86        {
 087            ArgumentNullException.ThrowIfNull(options);
 088            return new TemplateTransform(options).Apply(input, culture ?? CultureInfo.CurrentCulture);
 89        }
 90
 91        /// <summary>
 92        /// Resolves the template using the provided configuration action. Transformations are applied in the provided o
 93        /// </summary>
 94        /// <param name="configure">The configuration action to apply.</param>
 95        /// <param name="culture">The culture to use for the transformation.</param>
 96        /// <returns>The transformed string.</returns>
 97        public string ResolveTemplate(Action<TextTemplateOptionsBuilder> configure, CultureInfo? culture = null)
 98        {
 099            ArgumentNullException.ThrowIfNull(configure);
 0100            return TextTemplating.Create(configure).Apply(input, culture ?? CultureInfo.CurrentCulture);
 101        }
 102
 103        /// <summary>
 104        /// Resolves the template using the provided arguments. Transformations are applied in the provided order.
 105        /// </summary>
 106        /// <param name="arguments">The arguments to apply.</param>
 107        /// <param name="culture">The culture to use for the transformation.</param>
 108        /// <returns>The transformed string.</returns>
 109        public string ResolveTemplate(IEnumerable<KeyValuePair<string, object?>> arguments, CultureInfo? culture = null)
 110        {
 0111            ArgumentNullException.ThrowIfNull(arguments);
 0112            return TextTemplating.Create(x => x.WithArguments(arguments)).Apply(input, culture ?? CultureInfo.CurrentCul
 113        }
 114    }
 115}
 116