RFID.RFIDInterface.Source_GPIO_TypeConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() public method

public ConvertFrom ( System context, System culture, Object value ) : object
context System
culture System
value Object
return object
        public override object ConvertFrom(
            System.ComponentModel.ITypeDescriptorContext context,
            System.Globalization.CultureInfo             culture,
            Object                                       value
        )
        {
            if ( String.IsNullOrEmpty( value as string ) )
            {
                return null; // TODO : supply err msg
            }

            String[ ] gpioData = ( value as String ).Split( new Char[ ] { ',' } );

            if ( null == gpioData )
            {
                return null; // TODO : supply err msg ~ improper arg
            }

            if ( 2 > gpioData.Length || 3 < gpioData.Length )
            {
                return null; // TODO : supply err msg ~ improper arg count
            }

            try
            {
                rfid.Constants.GpioPin nativePin =
                    ( rfid.Constants.GpioPin ) Enum.Parse
                    (
                        typeof( Source_GPIO.OpAccess ),
                        gpioData[ 0 ]
                    );

                Source_GPIO.OpAccess access =
                    ( Source_GPIO.OpAccess ) Enum.Parse
                    (
                        typeof( Source_GPIO.OpAccess ),
                        gpioData[ 1 ]
                    );

                Source_GPIO.OpState state = Source_GPIO.OpState.FAILURE;

                if ( 3 == gpioData.Length )
                {
                    state = ( Source_GPIO.OpState ) Enum.Parse
                    (
                        typeof( Source_GPIO.OpState ),
                        gpioData[ 2 ]
                    );
                }

                Source_GPIO gpio = new Source_GPIO( nativePin, access );

                gpio.State  = state;
                gpio.Status = Source_GPIO.OpResult.FAILURE;

                return gpio;
            }
            catch ( Exception )
            {
                // TODO : supply err msg ~ bad arg

                return null;
            }
        }