References:
http://msdn.microsoft.com/en-us/library/system.enum.aspx - System.Enum
http://msdn.microsoft.com/en-us/library/ms229058.aspx - Enumeration Design
http://msdn.microsoft.com/en-us/library/cc138362.aspx - Enumeration Programming
Notes:
- System.Enum - Derived from ValueType
- The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong. Default is int
- Flag enumerations must have values explicitly assigned that are unique powers of two: 1 2 4 8 16 32 to work correctly.
- Important methods:
- Enum.TryParse()
- Enum.Parse()
- Enum.IsDefined()
- HasFlag()
- Enum.GetValues(typeof(MyEnumInstance))
- Enum.GetName(typeof(MyEnumInstance), myEnumVariable)
- You can't override ToString() for an Enum
- You can attach meta data to Enum types with Attribute mechanism and Extension Methods.
- (MyAttribute[]) MyEnumVariable.GetType().GetField( MyEnumVariable.ToString()).GetCustomAttributes(typeof(MyAttributes), false);
No comments:
Post a Comment