mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-25 16:19:11 +02:00
Create WireMock.Net.MimePart project (#1300)
* Create WireMock.Net.MimePart project * . * REFACTOR * ILRepack * -- * ... * x * x * . * fix * public class MimePartMatcher * shared * min * . * <!--<DelaySign>true</DelaySign>--> * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AnyOfTypes;
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Some extensions for AnyOf.
|
||||
/// </summary>
|
||||
public static class AnyOfExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the pattern.
|
||||
/// </summary>
|
||||
/// <param name="value">AnyOf type</param>
|
||||
/// <returns>string value</returns>
|
||||
public static string GetPattern(this AnyOf<string, StringPattern> value)
|
||||
{
|
||||
return value.IsFirst ? value.First : value.Second.Pattern;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the patterns.
|
||||
/// </summary>
|
||||
/// <param name="values">AnyOf types</param>
|
||||
/// <returns>string values</returns>
|
||||
public static string[] GetPatterns(this AnyOf<string, StringPattern>[] values)
|
||||
{
|
||||
return values.Select(GetPattern).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string-patterns to AnyOf patterns.
|
||||
/// </summary>
|
||||
/// <param name="patterns">The string patterns</param>
|
||||
/// <returns>The AnyOf patterns</returns>
|
||||
public static AnyOf<string, StringPattern>[] ToAnyOfPatterns(this IEnumerable<string> patterns)
|
||||
{
|
||||
return patterns.Select(p => p.ToAnyOfPattern()).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string-pattern to AnyOf pattern.
|
||||
/// </summary>
|
||||
/// <param name="pattern">The string pattern</param>
|
||||
/// <returns>The AnyOf pattern</returns>
|
||||
public static AnyOf<string, StringPattern> ToAnyOfPattern(this string pattern)
|
||||
{
|
||||
return new AnyOf<string, StringPattern>(pattern);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace WireMock.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Some extension methods for Enums.
|
||||
/// </summary>
|
||||
internal static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the fully qualified enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type.</typeparam>
|
||||
/// <param name="enumValue">The value.</param>
|
||||
/// <returns>The fully qualified enum value.</returns>
|
||||
public static string GetFullyQualifiedEnumValue<T>(this T enumValue)
|
||||
where T : struct, IConvertible
|
||||
{
|
||||
var type = typeof(T);
|
||||
|
||||
if (!type.GetTypeInfo().IsEnum)
|
||||
{
|
||||
throw new ArgumentException("T must be an enum");
|
||||
}
|
||||
|
||||
return $"{type.Namespace}.{type.Name}.{enumValue}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
|
||||
namespace WireMock.Extensions;
|
||||
|
||||
internal static class ExceptionExtensions
|
||||
{
|
||||
public static Exception? ToException(this Exception[] exceptions)
|
||||
{
|
||||
return exceptions.Length switch
|
||||
{
|
||||
1 => exceptions[0],
|
||||
> 1 => new AggregateException(exceptions),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user