public static DeviceState GetStateFromString( String state )
{
if ( Enum.IsDefined ( typeof ( DeviceState ), state ) ) {
return (DeviceState)Enum.Parse ( typeof ( DeviceState ), state, true );
} else {
foreach ( var fi in typeof ( DeviceState ).GetFields ( ) ) {
/*
FieldDisplayNameAttribute dna = ReflectionHelper.GetCustomAttribute<FieldDisplayNameAttribute> ( fi );
if ( dna != null ) {
if ( string.Compare ( dna.DisplayName, state, false ) == 0 ) {
return (DeviceState)fi.GetValue ( null );
}
} else { */
if ( string.Compare ( fi.Name, state, true ) == 0 ) {
return (DeviceState)fi.GetValue ( null );
}
// }
}
}
return DeviceState.Unknown;
}