Get a collection of flags from a flag value.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace Vestris.ResourceLib
{
/// <summary>
/// Resource utilities.
/// </summary>
public abstract class ResourceUtil
{
/// <summary>
/// Get a collection of flags from a flag value.
/// </summary>
/// <typeparam name="T">Flag collection type.</typeparam>
/// <param name="flagValue">Flag value.</param>
/// <returns>Collection of flags.</returns>
internal static List<string> FlagsToList<T>(UInt32 flagValue)
{
List<string> flags = new List<string>();
foreach (T f in Enum.GetValues(typeof(T)))
{
UInt32 f_ui = Convert.ToUInt32(f);
if ((flagValue & f_ui) > 0 || flagValue == f_ui)
{
flags.Add(f.ToString());
}
}
return flags;
}
}
}
Related examples in the same category