c# Programming Glossary: enumtype
Show Enum Description Instead of Name http://stackoverflow.com/questions/11439920/show-enum-description-instead-of-name though public static object GetValuesAndDescriptions Type enumType var values Enum.GetValues enumType .Cast object var valuesAndDescriptions.. Type enumType var values Enum.GetValues enumType .Cast object var valuesAndDescriptions from value in values..
AutoMapper: Mapping between a IDataReader and DTO object http://stackoverflow.com/questions/1973351/automapper-mapping-between-a-idatareader-and-dto-object else if entityField.Property.GetType .IsEnum Type enumType entityField.Property.GetType EnumConverter enumConverter new.. EnumConverter enumConverter new EnumConverter enumType object enumValue enumConverter.ConvertFrom dataRow entityField.DataFieldMapping.MappedField..
Get enum from enum attribute http://stackoverflow.com/questions/2787506/get-enum-from-enum-attribute Als GetEnumByStringValueAttribute string value Type enumType typeof Als foreach Enum val in Enum.GetValues enumType FieldInfo.. enumType typeof Als foreach Enum val in Enum.GetValues enumType FieldInfo fi enumType.GetField val.ToString StringValueAttribute.. foreach Enum val in Enum.GetValues enumType FieldInfo fi enumType.GetField val.ToString StringValueAttribute attributes StringValueAttribute..
Iterate over values in Flags Enum? http://stackoverflow.com/questions/4171140/iterate-over-values-in-flags-enum Enum private static IEnumerable Enum GetFlagValues Type enumType ulong flag 0x1 foreach var value in Enum.GetValues enumType.. ulong flag 0x1 foreach var value in Enum.GetValues enumType .Cast Enum ulong bits Convert.ToUInt64 value if bits 0L yield..
MVC3 Razor DropDownListFor Enums http://stackoverflow.com/questions/4656758/mvc3-razor-dropdownlistfor-enums value.ToString public static SelectList ToSelectList Type enumType string selectedItem List SelectListItem items new List SelectListItem.. new List SelectListItem foreach var item in Enum.GetValues enumType FieldInfo fi enumType.GetField item.ToString var attribute.. foreach var item in Enum.GetValues enumType FieldInfo fi enumType.GetField item.ToString var attribute fi.GetCustomAttributes..
C# - static types cannot be used as type arguments http://stackoverflow.com/questions/5858591/c-sharp-static-types-cannot-be-used-as-type-arguments null argName internal void ThrowNotInEnum Type enumType object value if Enum.IsDefined enumType value TraceAndThrow.. Type enumType object value if Enum.IsDefined enumType value TraceAndThrow new ArgumentOutOfRangeException Resources.ArgEnumIllegalVal.InvariantFormat..
Cast a property to its actual type dynamically using reflection http://stackoverflow.com/questions/907882/cast-a-property-to-its-actual-type-dynamically-using-reflection value return null if property.PropertyType.IsEnum Type enumType property.PropertyType if Enum.IsDefined enumType value return.. Type enumType property.PropertyType if Enum.IsDefined enumType value return Enum.Parse enumType value if property.PropertyType.. if Enum.IsDefined enumType value return Enum.Parse enumType value if property.PropertyType typeof bool return value 1 value..
|