Checks whether Enum instance are assigned or not - CSharp System

CSharp examples for System:Enum

Description

Checks whether Enum instance are assigned or not

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from w  ww  .  j  a  va 2 s  .  c  om

public class Main{
        /// <summary>
        /// Checks whether Enum instance are assigned or not
        /// </summary>
        /// <param name="Enum">Enum to evaluate</param>
        /// <param name="EnumHasZeroValue">Whether Enum has item with 0 value or not , Default is False . e.g. for SendStatus this param should be set to True</param>
        /// <returns></returns>
        public static bool IsEnumAssigned(object Enum,bool EnumHasZeroValue)
        {
            if (Enum == null)
                return false;

            if (Enum.ToString() == "-1")
                return false;

            if (!EnumHasZeroValue && Enum.ToString() == "0")
                return false;

            return true;
        }
        /// <summary>
        /// Checks whether Enum instance are assigned or not
        /// </summary>
        /// <param name="Enum">Enum to evaluate</param>
        /// <returns></returns>
        public static bool IsEnumAssigned(object Enum)
        {
            return IsEnumAssigned(Enum, false);
        }
}

Related Tutorials