本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
}
}
示例5: SetEnumEvent
private SetEnumEvent(CtorType ctorType, int position, Enum val, String name)
{
this.ctorType = ctorType;
this.position = position;
this.val = val;
this.name = name;
}
示例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);
}
示例7: Resource
public Resource(ResourceManager resourceManager, Enum stringResource)
{
ResourceManager = resourceManager;
StringResource = stringResource;
LastModified = DateTime.UtcNow;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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>();
}
示例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;
}
示例15: AddRoom
public Room AddRoom(Enum id)
{
var room = new Room(this, id.ToString());
_rooms.Add(id, room);
return room;
}