Sets the Enum flag on in the specified mask. - CSharp System

CSharp examples for System:Enum

Description

Sets the Enum flag on in the specified mask.

Demo Code


using System.Threading;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;
using System;/*from w  w w .jav  a  2  s . com*/

public class Main{
        /// <summary>
        /// Sets the flag on in the specified mask.
        /// </summary>
        /// <typeparam name="T">The flag type.</typeparam>
        /// <param name="mask">The mask to set flag on.</param>
        /// <param name="flag">The flag to set.</param>
        /// <returns>The mask with the flag set to on.</returns>
        public static T SetFlagOn<T>(this Enum mask, T flag)
            where T : struct, IComparable, IFormattable, IConvertible {
            ulong flagInt = Convert.ToUInt64(flag);
            ulong maskInt = Convert.ToUInt64(mask);

            maskInt |= flagInt;

            return ConvertFlag<T>(maskInt);
        }
}

Related Tutorials