protected string GetXmlValue(object obj, object parent, string elementName)
        {
            if (obj is string)
            {
                return((string)obj);
            }
            if (obj is Font)
            {
                return(SerializerBase.FontToString((Font)obj));
            }
            if (obj is Color)
            {
                return(SerializerBase.colorConverter.ConvertToString(null, CultureInfo.InvariantCulture, obj));
            }
            if (obj is Color[])
            {
                return(ColorArrayConverter.ColorArrayToString((Color[])obj));
            }
            if (obj is Image)
            {
                return(SerializerBase.ImageToString((Image)obj));
            }
            PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(parent)[elementName];

            if (propertyDescriptor != null && propertyDescriptor.Converter != null && propertyDescriptor.Converter.CanConvertTo(typeof(string)))
            {
                return(propertyDescriptor.Converter.ConvertToString(null, CultureInfo.InvariantCulture, obj));
            }
            return(obj.ToString());
        }
Beispiel #2
0
 protected void WritePropertyValue(object obj, object parent, string elementName, BinaryWriter writer)
 {
     writer.Write(SerializerBase.GetStringHashCode(elementName));
     if (obj is bool)
     {
         writer.Write((bool)obj);
     }
     else if (obj is double)
     {
         writer.Write((double)obj);
     }
     else if (obj is string)
     {
         writer.Write((string)obj);
     }
     else if (obj is int)
     {
         writer.Write((int)obj);
     }
     else if (obj is long)
     {
         writer.Write((long)obj);
     }
     else if (obj is float)
     {
         writer.Write((float)obj);
     }
     else if (obj.GetType().IsEnum)
     {
         string value = ((Enum)obj).ToString();
         writer.Write(value);
     }
     else if (obj is byte)
     {
         writer.Write((byte)obj);
     }
     else if (obj is Font)
     {
         writer.Write(SerializerBase.FontToString((Font)obj));
     }
     else if (obj is Color)
     {
         writer.Write(((Color)obj).ToArgb());
     }
     else if (obj is DateTime)
     {
         writer.Write(((DateTime)obj).Ticks);
     }
     else if (obj is Size)
     {
         writer.Write(((Size)obj).Width);
         writer.Write(((Size)obj).Height);
     }
     else if (obj is double[])
     {
         double[] array = (double[])obj;
         writer.Write(array.Length);
         double[] array2 = array;
         foreach (double value2 in array2)
         {
             writer.Write(value2);
         }
     }
     else if (obj is Color[])
     {
         Color[] array3 = (Color[])obj;
         writer.Write(array3.Length);
         Color[] array4 = array3;
         foreach (Color color in array4)
         {
             writer.Write(color.ToArgb());
         }
     }
     else if (obj is Image)
     {
         MemoryStream memoryStream = new MemoryStream();
         ((Image)obj).Save(memoryStream, ((Image)obj).RawFormat);
         int value3 = (int)memoryStream.Seek(0L, SeekOrigin.End);
         memoryStream.Seek(0L, SeekOrigin.Begin);
         writer.Write(value3);
         writer.Write(memoryStream.ToArray());
         memoryStream.Close();
     }
     else
     {
         if (!(obj is Margins))
         {
             throw new InvalidOperationException(SR.ExceptionChartSerializerBinaryTypeUnsupported(obj.GetType().ToString()));
         }
         writer.Write(((Margins)obj).Top);
         writer.Write(((Margins)obj).Bottom);
         writer.Write(((Margins)obj).Left);
         writer.Write(((Margins)obj).Right);
     }
 }