public void ConvertToInteger() { Assert.Equal(1, XmpUtils.ConvertToInteger("1")); Assert.Equal(1, XmpUtils.ConvertToInteger("001")); Assert.Equal(1, XmpUtils.ConvertToInteger("0x1")); Assert.Equal(15, XmpUtils.ConvertToInteger("0xF")); Assert.Equal(-1, XmpUtils.ConvertToInteger("-1")); Assert.Equal(123, XmpUtils.ConvertToInteger(" 123 ")); Assert.Throws <XmpException>(() => XmpUtils.ConvertToInteger(null)); Assert.Throws <XmpException>(() => XmpUtils.ConvertToInteger("Foo")); }
/// <summary> /// Evaluates a raw node value to the given value type, apply special /// conversions for defined types in XMP. /// </summary> /// <param name="valueType"> /// an int indicating the value type </param> /// <param name="propNode"> /// the node containing the value </param> /// <returns> Returns a literal value for the node. </returns> /// <exception cref="XmpException"> </exception> private object evaluateNodeValue(int valueType, XmpNode propNode) { object value; string rawValue = propNode.Value; switch (valueType) { case VALUE_BOOLEAN: value = XmpUtils.ConvertToBoolean(rawValue); break; case VALUE_INTEGER: value = XmpUtils.ConvertToInteger(rawValue); break; case VALUE_LONG: value = XmpUtils.ConvertToLong(rawValue); break; case VALUE_DOUBLE: value = XmpUtils.ConvertToDouble(rawValue); break; case VALUE_DATE: value = XmpUtils.ConvertToDate(rawValue); break; case VALUE_CALENDAR: IXmpDateTime dt = XmpUtils.ConvertToDate(rawValue); value = dt.Calendar; break; case VALUE_BASE64: value = XmpUtils.DecodeBase64(rawValue); break; default: // leaf values return empty string instead of null // for the other cases the converter methods provides a "null" // value. // a default value can only occur if this method is made public. value = rawValue != null || propNode.Options.CompositeProperty ? rawValue : ""; break; } return(value); }