Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
GeneralRe: code Pin
help as an alias21-Aug-07 1:08
help as an alias21-Aug-07 1:08 
QuestionHow to insert objects to a section in crystal report dynamically? Pin
getnanda@gmail.com20-Aug-07 18:10
getnanda@gmail.com20-Aug-07 18:10 
AnswerRe: How to insert objects to a section in crystal report dynamically? Pin
help as an alias20-Aug-07 18:23
help as an alias20-Aug-07 18:23 
GeneralRe: How to insert objects to a section in crystal report dynamically? Pin
getnanda@gmail.com20-Aug-07 18:27
getnanda@gmail.com20-Aug-07 18:27 
GeneralRe: How to insert objects to a section in crystal report dynamically? Pin
help as an alias21-Aug-07 1:17
help as an alias21-Aug-07 1:17 
Questiondeclaring xmlserializer where typeof is a class derived from arraylist Pin
cyn820-Aug-07 18:04
cyn820-Aug-07 18:04 
AnswerRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali20-Aug-07 23:03
Hessam Jalali20-Aug-07 23:03 
AnswerRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali20-Aug-07 23:11
Hessam Jalali20-Aug-07 23:11 
and these are the codes I modified and tested (I'm really sorry about what I sent two days ago it didn't work well in desrialization Frown | :( )

Here is Correct ones

 [XmlRoot("MyData")]
 [Serializable]
public class MyData
 {
     //it seems datas in each arraylist are the same type so if you're codinh in .NET2.0 or above use List<> instead of ArrayList

     ArrayList shapeTypeList;
     ArrayList colorList;
     ArrayList coordList;
     ArrayList sizeList;

     ArrayList graphicsPathDataList;

     [XmlArray("ShapeData")]
     [XmlArrayItem("Shape")]
     public ArrayList ShapeTypeList
     {
         get { return this.shapeTypeList; }
         set { this.shapeTypeList = value; }
     }

     [XmlArray("ColorData")]
     [XmlArrayItem("Color")]
     public ArrayList ColorList
     {
         get { return this.colorList; }
         set { this.colorList = value; }
     }

     [XmlArray("CoorinationData")]
     [XmlArrayItem("Coordination")]
     public ArrayList CoordList
     {
         get { return this.coordList; }
         set { this.coordList= value; }
     }

     [XmlArray("SizeData")]
     [XmlArrayItem("Size")]
     public ArrayList SizeList
     {
         get { return this.sizeList; }
         set { this.sizeList = value; }
     }

     [XmlArray("GPDDataCollection")]
     [XmlArrayItem("GPD",Type=typeof(GraphicsPathData))]
     public ArrayList GraphicsPathDataList
     {
         get { return this.graphicsPathDataList; }
         set { this.graphicsPathDataList = value; }
     }

     public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)
     {
         this.shapeTypeList = shape;
         this.colorList = color;
         this.coordList = coord;
         this.sizeList = size;
         this.graphicsPathDataList = gpd;
     }

     private MyData()
     {
     }

     static MyData BinLoad(string path)
     {
         BinaryFormatter binSer=new BinaryFormatter();
         FileStream fo=new  FileStream(path,FileMode.Open);

         object data=binSer.Deserialize(fo);
         fo.Close();

         return data as MyData;
     }

     void BinSerialize(string path)
     {
         BinaryFormatter binSer=new BinaryFormatter();
         FileStream fo=new  FileStream(path,FileMode.OpenOrCreate);

         binSer.Serialize(fo,this);
         fo.Close();
     }

     static MyData XmlLoad(string path)
     {
         XmlSerializer xmlSer=new XmlSerializer(typeof(MyData));
         FileStream fo=new  FileStream(path,FileMode.Open);

         object data=xmlSer.Deserialize(fo);
         fo.Close();

         return data as MyData;
     }

     void XmlSerialize(string path)
     {
         XmlSerializer xmlSer=new XmlSerializer(this.GetType());
         FileStream fo=new  FileStream(path,FileMode.OpenOrCreate);

         xmlSer.Serialize(fo,this);
         fo.Close();
     }

     public enum SerializeTo{XML,Binary};

     public void Serialize(string path,SerializeTo to)
     {
         if(to==SerializeTo.Binary)
             this.BinSerialize(path);
         else
             this.XmlSerialize(path);
     }

     public static MyData Load(string path,SerializeTo to)
     {
         if(to==SerializeTo.Binary)
             return BinLoad(path);
         else
             return XmlLoad(path);
     }

 }


and the GraphicspathData must be modified somewhat like this
[Serializable]
[XmlRoot("GraphicsPathData")]
[XmlInclude(typeof(GraphicsPathData))]
public class GraphicsPathData
{
    byte[] types;
    PointF[] points;
    FillMode fillMode;


    [XmlArray("Types")]
    public byte[] Types
    {
        get { return this.types; }
        set { this.types = value; }
    }


    [XmlArray("Points")]
    public PointF[] Points
    {
        get { return this.points; }
        set { this.points = value; }
    }


    [XmlElement("FillMode")]
    public FillMode FillMode
    {
        get { return this.fillMode; }
        set { this.fillMode = value; }
    }

    public GraphicsPathData(GraphicsPath gp)
    {
        this.types = gp.PathTypes;
        this.points = gp.PathPoints;
        this.fillMode = gp.FillMode;
    }

    private GraphicsPathData()
    {
    }

    public static System.IO.Stream Serialize(GraphicsPathData gpd)
    {
        System.IO.MemoryStream ms = new System.IO.MemoryStream();

        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        bf.Serialize(ms, gpd);
        ms.Flush();
        return ms;
    }

    public static GraphicsPathData Deserialize(System.IO.Stream stream)
    {
        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        object obj = bf.Deserialize(stream);
        GraphicsPathData gpd = obj as GraphicsPathData;
        return gpd;
    }

    public static GraphicsPath GetGraphicsPath(GraphicsPathData gpd)
    {
        return new GraphicsPath(gpd.points, gpd.types, gpd.fillMode);
    }

    public static GraphicsPath GetGraphicsPath(System.IO.Stream gpdStream)
    {
        return GetGraphicsPath(Deserialize(gpdStream));
    }
}


good luck Smile | :)
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist [modified] Pin
cyn821-Aug-07 17:01
cyn821-Aug-07 17:01 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali22-Aug-07 0:22
Hessam Jalali22-Aug-07 0:22 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
cyn822-Aug-07 0:29
cyn822-Aug-07 0:29 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali22-Aug-07 3:21
Hessam Jalali22-Aug-07 3:21 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist [modified] Pin
cyn822-Aug-07 21:48
cyn822-Aug-07 21:48 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali23-Aug-07 2:15
Hessam Jalali23-Aug-07 2:15 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
cyn823-Aug-07 16:29
cyn823-Aug-07 16:29 
GeneralRe: declaring xmlserializer where typeof is a class derived from arraylist Pin
Hessam Jalali23-Aug-07 23:47
Hessam Jalali23-Aug-07 23:47 
QuestionHow to "ping" command on Mono by C#? Pin
bug_aonz20-Aug-07 17:49
bug_aonz20-Aug-07 17:49 
AnswerRe: How to "ping" command on Mono by C#? Pin
Vasudevan Deepak Kumar20-Aug-07 21:32
Vasudevan Deepak Kumar20-Aug-07 21:32 
GeneralRe: How to "ping" command on Mono by C#? Pin
bug_aonz21-Aug-07 16:44
bug_aonz21-Aug-07 16:44 
QuestionInstalled software List Pin
Jeeva Jose20-Aug-07 17:15
Jeeva Jose20-Aug-07 17:15 
AnswerRe: Installed software List Pin
Scott Dorman20-Aug-07 17:24
professionalScott Dorman20-Aug-07 17:24 
QuestionC# and MATLAB Pin
TriBerryPowerBar20-Aug-07 15:17
TriBerryPowerBar20-Aug-07 15:17 
AnswerRe: C# and MATLAB Pin
Scott Dorman20-Aug-07 17:23
professionalScott Dorman20-Aug-07 17:23 
QuestionUpdater block - downloading updates from a server Pin
steve_rm20-Aug-07 11:33
steve_rm20-Aug-07 11:33 
QuestionIP Control Pin
Demian Panello20-Aug-07 9:29
Demian Panello20-Aug-07 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.