Exemplo n.º 1
0
 public string Serialize(object value)
 {
     if ((value == null) || (value == DBNull.Value))
     {
         return null;
     }
     if (value is Color)
     {
         return this.ColorToName((Color) value);
     }
     if (value is Font)
     {
         Font font1 = (Font) value;
         return string.Format(CultureInfo.InvariantCulture, "{0}, {1}pt, style={2}", new object[] { ((Font) value).Name, ((Font) value).Size, ((Font) value).Style });
     }
     if (value is string[])
     {
         return string.Join(",", (string[]) value);
     }
     if (value is Rectangle)
     {
         object[] args = new object[4];
         Rectangle rectangle = (Rectangle) value;
         args[0] = rectangle.X;
         Rectangle rectangle2 = (Rectangle) value;
         args[1] = rectangle2.Y;
         Rectangle rectangle3 = (Rectangle) value;
         args[2] = rectangle3.Width;
         Rectangle rectangle4 = (Rectangle) value;
         args[3] = rectangle4.Height;
         return string.Format("{0},{1},{2},{3}", args);
     }
     if (value is Point)
     {
         Point point = (Point) value;
         Point point2 = (Point) value;
         return string.Format("{0},{1}", point.X, point2.Y);
     }
     if (value is Size)
     {
         Size size = (Size) value;
         Size size2 = (Size) value;
         return string.Format("{0},{1}", size.Width, size2.Height);
     }
     if (value is Image)
     {
         Image image = (Image) value;
         MemoryStream stream = new MemoryStream();
         try
         {
             image.Save(stream, ImageFormat.Png);
         }
         catch
         {
             image.Save(stream, ImageFormat.Bmp);
         }
         return Convert.ToBase64String(stream.ToArray());
     }
     if (value is ImageList)
     {
         ImageList c = value as ImageList;
         ISite site = c.Site;
         if (!this.ImageLists.Contains(c))
         {
             this.ImageLists.Add(c);
         }
         if (((site == null) || (site.Name == null)) || (site.Name == ""))
         {
             string n = "imageList" + this.m_ILUnique;
             this.m_ILUnique++;
             foreach (ImageList list2 in this.ImageLists)
             {
                 if ((list2.Site != null) && (list2.Site.Name == n))
                 {
                     n = "imageList" + this.m_ILUnique;
                     this.m_ILUnique++;
                 }
             }
             if (site == null)
             {
                 site = new RTImageListSite(c, n);
             }
             else
             {
                 site.Name = n;
             }
             c.Site = site;
         }
         if (site != null)
         {
             return site.Name;
         }
         return null;
     }
     if (value is bool)
     {
         if (!((bool) value))
         {
             return "false";
         }
         return "true";
     }
     if (ReflectionHelper.IsType(value, "GradientColor"))
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
         Color color = (Color) properties["StartColor"].GetValue(value);
         Color color2 = (Color) properties["MiddleColor1"].GetValue(value);
         Color color3 = (Color) properties["MiddleColor2"].GetValue(value);
         Color color4 = (Color) properties["EndColor"].GetValue(value);
         object obj2 = properties["FillDirection"].GetValue(value);
         return string.Format("{0},{1},{2},{3},{4}", new object[] { this.ColorToName(color), this.ColorToName(color4), obj2, this.ColorToName(color2), this.ColorToName(color3) });
     }
     return value.ToString();
 }
Exemplo n.º 2
0
 public string Serialize(object value)
 {
     if ((value == null) || (value == DBNull.Value))
     {
         return(null);
     }
     if (value is Color)
     {
         return(this.ColorToName((Color)value));
     }
     if (value is Font)
     {
         Font font1 = (Font)value;
         return(string.Format(CultureInfo.InvariantCulture, "{0}, {1}pt, style={2}", new object[] { ((Font)value).Name, ((Font)value).Size, ((Font)value).Style }));
     }
     if (value is string[])
     {
         return(string.Join(",", (string[])value));
     }
     if (value is Rectangle)
     {
         object[]  args      = new object[4];
         Rectangle rectangle = (Rectangle)value;
         args[0] = rectangle.X;
         Rectangle rectangle2 = (Rectangle)value;
         args[1] = rectangle2.Y;
         Rectangle rectangle3 = (Rectangle)value;
         args[2] = rectangle3.Width;
         Rectangle rectangle4 = (Rectangle)value;
         args[3] = rectangle4.Height;
         return(string.Format("{0},{1},{2},{3}", args));
     }
     if (value is Point)
     {
         Point point  = (Point)value;
         Point point2 = (Point)value;
         return(string.Format("{0},{1}", point.X, point2.Y));
     }
     if (value is Size)
     {
         Size size  = (Size)value;
         Size size2 = (Size)value;
         return(string.Format("{0},{1}", size.Width, size2.Height));
     }
     if (value is Image)
     {
         Image        image  = (Image)value;
         MemoryStream stream = new MemoryStream();
         try
         {
             image.Save(stream, ImageFormat.Png);
         }
         catch
         {
             image.Save(stream, ImageFormat.Bmp);
         }
         return(Convert.ToBase64String(stream.ToArray()));
     }
     if (value is ImageList)
     {
         ImageList c    = value as ImageList;
         ISite     site = c.Site;
         if (!this.ImageLists.Contains(c))
         {
             this.ImageLists.Add(c);
         }
         if (((site == null) || (site.Name == null)) || (site.Name == ""))
         {
             string n = "imageList" + this.m_ILUnique;
             this.m_ILUnique++;
             foreach (ImageList list2 in this.ImageLists)
             {
                 if ((list2.Site != null) && (list2.Site.Name == n))
                 {
                     n = "imageList" + this.m_ILUnique;
                     this.m_ILUnique++;
                 }
             }
             if (site == null)
             {
                 site = new RTImageListSite(c, n);
             }
             else
             {
                 site.Name = n;
             }
             c.Site = site;
         }
         if (site != null)
         {
             return(site.Name);
         }
         return(null);
     }
     if (value is bool)
     {
         if (!((bool)value))
         {
             return("false");
         }
         return("true");
     }
     if (ReflectionHelper.IsType(value, "GradientColor"))
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);
         Color  color  = (Color)properties["StartColor"].GetValue(value);
         Color  color2 = (Color)properties["MiddleColor1"].GetValue(value);
         Color  color3 = (Color)properties["MiddleColor2"].GetValue(value);
         Color  color4 = (Color)properties["EndColor"].GetValue(value);
         object obj2   = properties["FillDirection"].GetValue(value);
         return(string.Format("{0},{1},{2},{3},{4}", new object[] { this.ColorToName(color), this.ColorToName(color4), obj2, this.ColorToName(color2), this.ColorToName(color3) }));
     }
     return(value.ToString());
 }