Habanero.Base.DataMappers.ByteArrayDataMapper.TryParsePropValue C# (CSharp) Method

TryParsePropValue() public method

This method provides the functionality to convert any object to the appropriate type for this mapper. The default behaviour only handles null values, empty strings and DBNull.Value and parses all three to null. This method should be overridden in subtypes to parse values to the type you want.
public TryParsePropValue ( object valueToParse, object &returnValue ) : bool
valueToParse object The value to be attempted to parse
returnValue object the parsed value, if parsing was successful
return bool
        public override bool TryParsePropValue(object valueToParse, out object returnValue)
        {
            if (base.TryParsePropValue(valueToParse, out returnValue)) return true;
            if (valueToParse is byte[])
            {
                returnValue = valueToParse;
                return true;
            } 
            if (valueToParse is String)
            {
                var bytes = Convert.FromBase64String((string) valueToParse);
                returnValue = bytes;
                return true;
            }
            returnValue = null;
            return false;
        }

Usage Example

        public void TryParsePropValue_WorksForNull()
        {
            //---------------Set up test pack-------------------
            var dataMapper = new ByteArrayDataMapper();
            object parsedValue;
            //---------------Execute Test ----------------------
            var parseSucceed = dataMapper.TryParsePropValue(null, out parsedValue);

            //---------------Test Result -----------------------
            Assert.IsTrue(parseSucceed);
            Assert.IsNull(parsedValue);
        }
All Usage Examples Of Habanero.Base.DataMappers.ByteArrayDataMapper::TryParsePropValue