File size: 2,200 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Globalization;
using System.Management.Automation.SecurityAccountsManager.Native;
namespace System.Management.Automation.SecurityAccountsManager
{
/// <summary>
/// Contains utility functions for formatting localizable strings.
/// </summary>
internal class StringUtil
{
/// <summary>
/// Private constructor to present auto-generation of a default constructor with greater accessibility.
/// </summary>
private StringUtil()
{
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static string Format(string str)
{
return string.Format(CultureInfo.CurrentCulture, str);
}
internal static string Format(string fmt, string p0)
{
return string.Format(CultureInfo.CurrentCulture, fmt, p0);
}
internal static string Format(string fmt, string p0, string p1)
{
return string.Format(CultureInfo.CurrentCulture, fmt, p0, p1);
}
internal static string Format(string fmt, uint p0)
{
return string.Format(CultureInfo.CurrentCulture, fmt, p0);
}
internal static string Format(string fmt, int p0)
{
return string.Format(CultureInfo.CurrentCulture, fmt, p0);
}
internal static string FormatMessage(uint messageId, string[] args)
{
var message = new System.Text.StringBuilder(256);
UInt32 flags = Win32.FORMAT_MESSAGE_FROM_SYSTEM;
if (args == null)
flags |= Win32.FORMAT_MESSAGE_IGNORE_INSERTS;
else
flags |= Win32.FORMAT_MESSAGE_ARGUMENT_ARRAY;
var length = Win32.FormatMessage(flags, IntPtr.Zero, messageId, 0, message, 256, args);
if (length > 0)
return message.ToString();
return null;
}
internal static string GetSystemMessage(uint messageId)
{
return FormatMessage(messageId, null);
}
}
}
|