Ejemplo n.º 1
0
        /// <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>
        internal static string SerializeNodeValue(object value)
        {
            string strValue;

            if (value == null)
            {
                strValue = null;
            }
            else if (value is bool?)
            {
                strValue = XMPUtils.ConvertFromBoolean((bool)((bool?)value));
            }
            else if (value is int?)
            {
                strValue = XMPUtils.ConvertFromInteger((int)((int?)value));
            }
            else if (value is long?)
            {
                strValue = XMPUtils.ConvertFromLong((long)((long?)value));
            }
            else if (value is double?)
            {
                strValue = XMPUtils.ConvertFromDouble((double)((double?)value));
            }
            else if (value is XMPDateTime)
            {
                strValue = XMPUtils.ConvertFromDate((XMPDateTime)value);
            }
            else if (value is XmpCalendar)
            {
                XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((XmpCalendar)value);
                strValue = XMPUtils.ConvertFromDate(dt);
            }
            else if (value is byte[])
            {
                strValue = XMPUtils.EncodeBase64((byte[])value);
            }
            else
            {
                strValue = value.ToString();
            }

            return(strValue != null?Utils.RemoveControlChars(strValue) : null);
        }
Ejemplo n.º 2
0
        /// <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>
        internal static string SerializeNodeValue(object value)
        {
            string strValue;

            if (value == null)
            {
                strValue = null;
            }
            else
            {
                if (value is bool)
                {
                    strValue = XMPUtils.ConvertFromBoolean(((bool)value));
                }
                else
                {
                    if (value is int)
                    {
                        strValue = XMPUtils.ConvertFromInteger(((int)value).IntValue());
                    }
                    else
                    {
                        if (value is long)
                        {
                            strValue = XMPUtils.ConvertFromLong(((long)value).LongValue());
                        }
                        else
                        {
                            if (value is double)
                            {
                                strValue = XMPUtils.ConvertFromDouble(((double)value).DoubleValue());
                            }
                            else
                            {
                                if (value is XMPDateTime)
                                {
                                    strValue = XMPUtils.ConvertFromDate((XMPDateTime)value);
                                }
                                else
                                {
                                    if (value is Sharpen.GregorianCalendar)
                                    {
                                        XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((Sharpen.GregorianCalendar)value);
                                        strValue = XMPUtils.ConvertFromDate(dt);
                                    }
                                    else
                                    {
                                        if (value is sbyte[])
                                        {
                                            strValue = XMPUtils.EncodeBase64((sbyte[])value);
                                        }
                                        else
                                        {
                                            strValue = value.ToString();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(strValue != null?Utils.RemoveControlChars(strValue) : null);
        }