TryParsePropValue() 공개 메소드

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
리턴 bool
예제 #1
0
        public void TryParsePropValue_WorksForNull()
        {
            //---------------Set up test pack-------------------
            var dataMapper = new ImageDataMapper();
            object parsedValue;
            //---------------Execute Test ----------------------
            var parseSucceed = dataMapper.TryParsePropValue(null, out parsedValue);

            //---------------Test Result -----------------------
            Assert.IsTrue(parseSucceed);
            Assert.IsNull(parsedValue);
        }
예제 #2
0
        public void TryParsePropValue_WorksForImage()
        {
            //---------------Set up test pack-------------------
            var dataMapper = new ImageDataMapper();
            var valueToParse = new System.Drawing.Bitmap(100, 100);
            object parsedValue;
            //---------------Execute Test ----------------------
            var parseSucceed = dataMapper.TryParsePropValue(valueToParse, out parsedValue);

            //---------------Test Result -----------------------
            Assert.IsTrue(parseSucceed);
            Assert.AreSame(valueToParse, parsedValue);
        }
예제 #3
0
 public void TryParsePropValue_ConvertsStringToImage()
 {
     //---------------Set up test pack-------------------
     var dataMapper = new ImageDataMapper();
     var img = new System.Drawing.Bitmap(100, 100);
     var valueToParse = dataMapper.ConvertValueToString(img);
     object parsedValue;
     //---------------Execute Test ----------------------
     var parseSucceed = dataMapper.TryParsePropValue(valueToParse, out parsedValue);
     //---------------Test Result -----------------------
     Assert.IsTrue(parseSucceed);
     Assert.IsInstanceOf(typeof(System.Drawing.Bitmap), parsedValue);
     Assert.AreEqual(img.Width, ((System.Drawing.Bitmap) parsedValue).Width);
     Assert.AreEqual(img.Height, ((System.Drawing.Bitmap) parsedValue).Height);
 }
예제 #4
0
 public void TryParsePropValue_FailsForOtherTypes()
 {
     //---------------Set up test pack-------------------
     var dataMapper = new ImageDataMapper();
     object parsedValue;
     //---------------Execute Test ----------------------
     var parsedSucceed = dataMapper.TryParsePropValue(3, out parsedValue);
     //---------------Test Result -----------------------
     Assert.IsFalse(parsedSucceed);
 }