/// <summary> /// Converts the node value to string, apply special conversions for defined /// types in XMP. /// </summary> /// <param name="value">the node value to set</param> /// <returns>Returns the String representation of the node value.</returns> private static string SerializeNodeValue(object value) { if (value == null) { return(null); } if (value is bool) { return(XmpCore.XmpUtils.ConvertFromBoolean((bool)value)); } if (value is int) { return(XmpCore.XmpUtils.ConvertFromInteger((int)value)); } if (value is long) { return(XmpCore.XmpUtils.ConvertFromLong((long)value)); } if (value is double) { return(XmpCore.XmpUtils.ConvertFromDouble((double)value)); } string strValue; var dateTime = value as IXmpDateTime; if (dateTime != null) { strValue = XmpCore.XmpUtils.ConvertFromDate(dateTime); } else { var calendar = value as GregorianCalendar; if (calendar != null) { var dt = XmpDateTimeFactory.CreateFromCalendar(calendar); strValue = XmpCore.XmpUtils.ConvertFromDate(dt); } else { var sbytes = value as byte[]; strValue = sbytes != null?XmpCore.XmpUtils.EncodeBase64(sbytes) : value.ToString(); } } return(strValue != null?Utils.RemoveControlChars(strValue) : null); }
/// <summary> /// Converts the node value to string, apply special conversions for defined /// types in XMP. /// </summary> /// <param name="value">the node value to set</param> /// <returns>Returns the String representation of the node value.</returns> private static string SerializeNodeValue(object value) { switch (value) { case null: return(null); case bool b: return(XmpCore.XmpUtils.ConvertFromBoolean(b)); case int i: return(XmpCore.XmpUtils.ConvertFromInteger(i)); case long l: return(XmpCore.XmpUtils.ConvertFromLong(l)); case double d: return(XmpCore.XmpUtils.ConvertFromDouble(d)); } string strValue; switch (value) { case IXmpDateTime dateTime: strValue = XmpCore.XmpUtils.ConvertFromDate(dateTime); break; case GregorianCalendar calendar: var dt = XmpDateTimeFactory.CreateFromCalendar(calendar); strValue = XmpCore.XmpUtils.ConvertFromDate(dt); break; default: strValue = value is byte[] sbytes?XmpCore.XmpUtils.EncodeBase64(sbytes) : value.ToString(); break; } return(strValue != null?Utils.RemoveControlChars(strValue) : null); }
/** * Date/Time utilities */ private static void CoverDateTime() { writeMajorLabel("Test date/time utilities and special values"); var date1 = XmpDateTimeFactory.Create(2000, 1, 31, 12, 34, 56, -1); date1.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("PST"); var date2 = XmpDateTimeFactory.Create(0, 0, 0, 0, 0, 0, 0); GregorianCalendar cal = new GregorianCalendar(2007, 1, 28); var date3 = XmpDateTimeFactory.CreateFromCalendar(cal); var currentDateTime = XmpDateTimeFactory.GetCurrentDateTime(); log.WriteLine("Print date 2000 Jan 31 12:34:56 PST = {0}", date1); log.WriteLine("Print zero date = {0}", date2); log.WriteLine("Print date created by a calendar = {0}", date3); log.WriteLine("Print current date = {0}", currentDateTime); log.WriteLine(); }