當前位置: 首頁>>代碼示例>>C#>>正文


C# System.Enum類代碼示例

本文整理匯總了C#中System.Enum的典型用法代碼示例。如果您正苦於以下問題:C# Enum類的具體用法?C# Enum怎麽用?C# Enum使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Enum類屬於System命名空間,在下文中一共展示了Enum類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ValuePair

		static KeyInfo ValuePair(Enum token, object value)
		{
			KeyInfo k=new KeyInfo();
			k.ki_key=(int)(object)token;
			k.ki_name=token.ToString();
			return k;
		}
開發者ID:LogoPhonix,項目名稱:libgeotiff.net,代碼行數:7,代碼來源:geonames.cs

示例2: MapListener

		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void MapListener(IEventDispatcher dispatcher, Enum type, Delegate listener, Type eventClass = null)
		{
			if (eventClass == null)
			{	
				eventClass = typeof(Event);
			}

			List<EventMapConfig> currentListeners = _suspended ? _suspendedListeners : _listeners;

			EventMapConfig config;

			int i = currentListeners.Count;

			while (i-- > 0) 
			{
				config = currentListeners [i];
				if (config.Equals (dispatcher, type, listener, eventClass))
					return;
			}

			Delegate callback = eventClass == typeof(Event) ? listener : (Action<IEvent>)delegate(IEvent evt){
				RouteEventToListener(evt, listener, eventClass);
			};

			config = new EventMapConfig (dispatcher, type, listener, eventClass, callback);

			currentListeners.Add (config);

			if (!_suspended) 
			{
				dispatcher.AddEventListener (type, callback);
			}
		}
開發者ID:mikecann,項目名稱:robotlegs-sharp-framework,代碼行數:37,代碼來源:EventMap.cs

示例3: GetStringValue

        public static string GetStringValue(Enum value)
        {
            string output;
            var type = value.GetType();

            if (StringValues.ContainsKey(value))
            {
                output = StringValues[value].Value;
            }
            else
            {
                var fi = type.GetField(value.ToString());
                var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false)
                    as StringValueAttribute[];
                if (attrs != null && attrs.Length > 0)
                {
                    output = attrs[0].Value;
                    // Put it in the cache.
                    lock(StringValues)
                    {
                        // Double check
                        if (!StringValues.ContainsKey(value))
                        {
                            StringValues.Add(value, attrs[0]);
                        }
                    }
                }
                else
                {
                    return value.ToString();
                }
            }

            return output;
        }
開發者ID:niuxianghui,項目名稱:SkinsModify,代碼行數:35,代碼來源:EnumUtils.cs

示例4: SelectConcept

 public override void SelectConcept(Enum concept)
 {
     base.SelectConcept(concept);
     if(concept.GetType().Equals(typeof(DataAccessConceptsList)))
     {
         switch((DataAccessConceptsList)concept)
         {
             case DataAccessConceptsList.WorkingWithFilesExamples:
                 conceptExecutionClass = new WorkingWithFilesExamples();
                 break;
             case DataAccessConceptsList.WorkingWithStreams:
                 conceptExecutionClass = new WorkingWithStreams();
                 break;
             case DataAccessConceptsList.WorkingWithADO_DOTNET_Concepts:
                 conceptExecutionClass = new WorkingWithADO_DOTNET_Concepts();
                 break;
             case DataAccessConceptsList.WorkingWithXMLConcepts:
                 conceptExecutionClass = new WorkingWithXMLExamples();
                 break;
             case DataAccessConceptsList.LINQExamples:
                 conceptExecutionClass = new LINQExamples();
                 break;
             case DataAccessConceptsList.SerializationAndDeserializationExamples:
                 conceptExecutionClass = new SerializationAndDeserializationExamples();
                 break;
             case DataAccessConceptsList.ImplementingClassHierarchy:
                 conceptExecutionClass = new ClassHierarchyExample();
                 break;
         }
     }
 }
開發者ID:mayankaggarwal,項目名稱:MyConcepts,代碼行數:31,代碼來源:ConceptSelectionClass.cs

示例5: SetEnumEvent

 private SetEnumEvent(CtorType ctorType, int position, Enum val, String name)
 {
     this.ctorType = ctorType;
     this.position = position;
     this.val = val;
     this.name = name;
 }
開發者ID:spib,項目名稱:nhcontrib,代碼行數:7,代碼來源:SetEnumEvent.cs

示例6: BunnyMask

 public int BunnyMask(GUIContent content, Enum enumValue)
 {
     var enumType = enumValue.GetType();
     var enumNames = Enum.GetNames(enumType);
     var enumValues = Enum.GetValues(enumType) as int[];
     return BunnyMask(content, Convert.ToInt32(enumValue), enumValues, enumNames);
 }
開發者ID:srndpty,項目名稱:VFW,代碼行數:7,代碼來源:Masks.cs

示例7: Resource

        public Resource(ResourceManager resourceManager, Enum stringResource)
        {
            ResourceManager = resourceManager;
            StringResource = stringResource;

            LastModified = DateTime.UtcNow;
        }
開發者ID:ducas,項目名稱:MicroWebServer,代碼行數:7,代碼來源:Resource.cs

示例8: getPrev

 public FingerName getPrev(Enum current)
 {
     //set current index to last
     int currentIdx = 5;
     //initialize a Enum FingerName
     FingerName f = FingerName.UNKNOWN;
     //loop to find the current Enum index and value
     foreach (var value in Enum.GetValues(typeof(FingerName)))
     {
         if (current == value)
         {
             f = (FingerName)value;
             break;
         }
         else
         {
             currentIdx--;
         }
     }
     //minus 1 to get previous index of Enum
     int prevIdx = currentIdx - 1;
     //check if previous index is more than 0
     if (prevIdx < 0)
     {
         prevIdx = (FingerName.GetValues(typeof(FingerName)).Length) - 1;
     }
     //return the value of previous Enum
     return f;
 }
開發者ID:hzhiguang,項目名稱:AbuseAnalysis,代碼行數:29,代碼來源:FingerName.cs

示例9: getEnumHttpResponse

        /// <summary>
        /// Returns the string version of a http status response code
        /// </summary>
        /// <param name="statusCode"></param>
        /// <returns></returns>
        public static string getEnumHttpResponse(Enum statusCode)
        {
            string _httpResponse = "";

            switch (getEnumValue(statusCode))
            {
                case 200:
                    _httpResponse = "HTTP/1.1 200 OK";
                    break;

                case 404:
                    _httpResponse = "HTTP/1.1 404 Not Found";
                    break;

                case 423:
                    _httpResponse = "HTTP/1.1 423 Locked";
                    break;

                case 424:
                    _httpResponse = "HTTP/1.1 424 Failed Dependency";
                    break;

                case 507:
                    _httpResponse = "HTTP/1.1 507 Insufficient Storage";
                    break;

                default:
                    break;
            }

            return _httpResponse;
        }
開發者ID:tiernano,項目名稱:HojuWebDisk,代碼行數:37,代碼來源:WebDavHelper.cs

示例10: HasFlag

        public static bool HasFlag(this Enum enumRef, Enum flag)
        {
            long value = Convert.ToInt64(enumRef);
            long flagVal = Convert.ToInt64(flag);

            return (value & flagVal) == flagVal;
        }
開發者ID:kouseki926,項目名稱:sharpcompress,代碼行數:7,代碼來源:EnumExtensions.cs

示例11: getNext

 public FingerName getNext(Enum current)
 {
     //set current index to 0
     int currentIdx = 0;
     //initialize a Enum FingerName
     FingerName f = FingerName.UNKNOWN;
     //loop to find the current Enum index and value
     foreach (var value in Enum.GetValues(typeof(FingerName)))
     {
         if (current == value)
         {
             f = (FingerName)value;
             break;
         }
         else
         {
             currentIdx++;
         }
     }
     //add 1 to get next index of Enum
     int nextIdx = currentIdx + 1;
     //check if next index value is UNKNOWN
     if (nextIdx == Enum.GetValues(typeof(FingerName)).Length)
     {
         nextIdx = 0;
     }
     //return the value of next Enum
     return f;
 }
開發者ID:hzhiguang,項目名稱:AbuseAnalysis,代碼行數:29,代碼來源:FingerName.cs

示例12: GetStringValue

        public static string GetStringValue(Enum value)
        {
            string output = null;
            Type type = value.GetType();

            //Check first in our cached results...
            if (_stringValues.ContainsKey(value))
                output = (_stringValues[value] as StringValueAttribute).Value;
            else
            {
                //Look for our 'StringValueAttribute' 
                //in the field's custom attributes
                FieldInfo fi = type.GetField(value.ToString());
                StringValueAttribute[] attrs =
                   fi.GetCustomAttributes(typeof(StringValueAttribute),
                                           false) as StringValueAttribute[];
                if (attrs.Length > 0)
                {
                    _stringValues.Add(value, attrs[0]);
                    output = attrs[0].Value;
                }
            }

            return output;
        }
開發者ID:ikeough,項目名稱:GRegClientNET,代碼行數:25,代碼來源:Utilities.cs

示例13: GetFlags

 private static IEnumerable<Enum> GetFlags(Enum value, Enum[] values)
 {
     ulong bits = Convert.ToUInt64(value);
     List<Enum> results = new List<Enum>();
     for (int i = values.Length - 1; i >= 0; i--)
     {
         ulong mask = Convert.ToUInt64(values[i]);
         if (i == 0 && mask == 0L)
         {
             break;
         }
         if ((bits & mask) == mask)
         {
             results.Add(values[i]);
             bits -= mask;
         }
     }
     if (bits != 0L)
     {
         return Enumerable.Empty<Enum>();
     }
     if (Convert.ToUInt64(value) != 0L)
     {
         return results.Reverse<Enum>();
     }
     if (bits == Convert.ToUInt64(value) && values.Length > 0 && Convert.ToUInt64(values[0]) == 0L)
     {
         return values.Take(1);
     }
     return Enumerable.Empty<Enum>();
 }
開發者ID:jandppw,項目名稱:ppwcode-recovered-from-google-code,代碼行數:31,代碼來源:EnumExtensions.cs

示例14: HasFlag

        public static bool HasFlag(this Enum thisInstance, Enum flag)
        {
            ulong instanceVal = Convert.ToUInt64(thisInstance);
            ulong flagVal = Convert.ToUInt64(flag);

            return (instanceVal & flagVal) == flagVal;
        }
開發者ID:Chavjoh,項目名稱:RssSimpleStream,代碼行數:7,代碼來源:FrameworkHelper.cs

示例15: AddRoom

        public Room AddRoom(Enum id)
        {
            var room = new Room(this, id.ToString());
            _rooms.Add(id, room);

            return room;
        }
開發者ID:rishabhbanga,項目名稱:CK.HomeAutomation,代碼行數:7,代碼來源:Home.cs


注:本文中的System.Enum類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。