예제 #1
0
        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());
        }
예제 #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);
         return;
     }
     if (obj is double)
     {
         writer.Write((double)obj);
         return;
     }
     if (obj is string)
     {
         writer.Write((string)obj);
         return;
     }
     if (obj is int)
     {
         writer.Write((int)obj);
         return;
     }
     if (obj is long)
     {
         writer.Write((long)obj);
         return;
     }
     if (obj is float)
     {
         writer.Write((float)obj);
         return;
     }
     if (obj.GetType().IsEnum)
     {
         string value = ((Enum)obj).ToString();
         writer.Write(value);
         return;
     }
     if (obj is byte)
     {
         writer.Write((byte)obj);
         return;
     }
     if (obj is Font)
     {
         writer.Write(SerializerBase.FontToString((Font)obj));
         return;
     }
     if (obj is Color)
     {
         writer.Write(((Color)obj).ToArgb());
         return;
     }
     if (obj is DateTime)
     {
         writer.Write(((DateTime)obj).Ticks);
         return;
     }
     if (obj is Size)
     {
         writer.Write(((Size)obj).Width);
         writer.Write(((Size)obj).Height);
         return;
     }
     if (obj is double[])
     {
         double[] array = (double[])obj;
         writer.Write(array.Length);
         double[] array2 = array;
         foreach (double value2 in array2)
         {
             writer.Write(value2);
         }
         return;
     }
     if (obj is Color[])
     {
         Color[] array3 = (Color[])obj;
         writer.Write(array3.Length);
         Color[] array4 = array3;
         for (int j = 0; j < array4.Length; j++)
         {
             Color color = array4[j];
             writer.Write(color.ToArgb());
         }
         return;
     }
     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();
         return;
     }
     if (obj is Margins)
     {
         writer.Write(((Margins)obj).Top);
         writer.Write(((Margins)obj).Bottom);
         writer.Write(((Margins)obj).Left);
         writer.Write(((Margins)obj).Right);
         return;
     }
     throw new InvalidOperationException(SR.ExceptionChartSerializerBinaryTypeUnsupported(obj.GetType().ToString()));
 }