main
cs 40 lines 1.6 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixInternal.Core.TestPackage
4 {
5 using System;
6 using WixToolset.Data;
7
8 /// <summary>
9 /// Utility class to help format messages.
10 /// </summary>
11 public static class WixMessageFormatter
12 {
13 /// <summary>
14 /// Formats a message into a standard string with the level, id, and message.
15 /// </summary>
16 /// <param name="message">Message to format</param>
17 /// <returns>Standard message formatting with the level, id, and message.</returns>
18 public static string FormatMessage(Message message)
19 {
20 return $"{message.Level} {message.Id}: {message}";
21 }
22
23 /// <summary>
24 /// Formats a message into a standard string with the level, id, and message.
25 /// </summary>
26 /// <param name="message">Message to format</param>
27 /// <param name="replacementMatch">Match for the replacement</param>
28 /// <param name="replacement">Value to replace</param>
29 /// <returns>Standard message formatting with the level, id, and message.</returns>
30 public static string FormatMessage(Message message, string replacementMatch, string replacement)
31 {
32 if (replacement is null)
33 {
34 throw new ArgumentNullException(nameof(replacement));
35 }
36
37 return $"{message.Level} {message.Id}: {message}".Replace(replacementMatch, replacement);
38 }
39 }
40 }