Index: src/Common/SharpMap/Utilities/Surrogates.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/SharpMap/Utilities/Surrogates.cs (.../Surrogates.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/SharpMap/Utilities/Surrogates.cs (.../Surrogates.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -22,183 +22,193 @@ namespace SharpMap.Utilities { - /// - /// Helper class for serializing System.Drawing.Pen and System.Drawing.Brush - /// - public class Surrogates - { - /// - /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush - /// - /// SurrogateSelector - public static SurrogateSelector GetSurrogateSelectors() - { - System.Runtime.Serialization.SurrogateSelector ss = new System.Runtime.Serialization.SurrogateSelector(); - ss.AddSurrogate(typeof(Pen), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.PenSurrogate()); - ss.AddSurrogate(typeof(SolidBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.SolidBrushSurrogate()); - ss.AddSurrogate(typeof(System.Drawing.TextureBrush), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.TextureBrushSurrogate()); - ss.AddSurrogate(typeof(Matrix), new StreamingContext(StreamingContextStates.All), new SharpMap.Utilities.Surrogates.MatrixSurrogate()); - return ss; - } + /// + /// Helper class for serializing System.Drawing.Pen and System.Drawing.Brush + /// + public class Surrogates + { + /// + /// Gets the surrogate selecteds for System.Drawing.Pen and System.Drawing.Brush + /// + /// SurrogateSelector + public static SurrogateSelector GetSurrogateSelectors() + { + SurrogateSelector ss = new SurrogateSelector(); + ss.AddSurrogate(typeof(Pen), new StreamingContext(StreamingContextStates.All), new PenSurrogate()); + ss.AddSurrogate(typeof(SolidBrush), new StreamingContext(StreamingContextStates.All), new SolidBrushSurrogate()); + ss.AddSurrogate(typeof(TextureBrush), new StreamingContext(StreamingContextStates.All), new TextureBrushSurrogate()); + ss.AddSurrogate(typeof(Matrix), new StreamingContext(StreamingContextStates.All), new MatrixSurrogate()); + return ss; + } - /// - /// Surrogate class used for serializing System.Drawing.SolidBrush - /// - public class SolidBrushSurrogate : ISerializationSurrogate - { - /// - /// Populates the provided SerializationInfo with the data needed to serialize the object. - /// - /// The object to serialize. - /// The SerializationInfo to populate with data. - /// The destination for this serialization. - public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) - { - System.Drawing.SolidBrush brush = (System.Drawing.SolidBrush)obj; - info.AddValue("Color", brush.Color); - } - /// - /// Populates the object using the information in the SerializationInfo - /// - /// The object to populate. - /// The information to populate the object. - /// The source from which the object is deserialized. - /// The surrogate selector where the search for a compatible surrogate begins. - /// - public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) - { - SolidBrush brush = new SolidBrush((Color)info.GetValue("Color", typeof(Color))); - return null; - } - } + /// + /// Surrogate class used for serializing System.Drawing.Drawing2D.Matrix + /// + public class MatrixSurrogate : ISerializationSurrogate + { + /// + /// Populates the provided SerializationInfo with the data needed to serialize the object. + /// + /// The object to serialize. + /// The SerializationInfo to populate with data. + /// The destination for this serialization. + public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) + { + Matrix mat = (Matrix) obj; + info.AddValue("Elements", mat.Elements); + } - /// - /// Surrogate class used for serializing System.Drawing.TextureBrush - /// - public class TextureBrushSurrogate : ISerializationSurrogate - { - /// - /// Populates the provided SerializationInfo with the data needed to serialize the object. - /// - /// The object to serialize. - /// The SerializationInfo to populate with data. - /// The destination for this serialization. - public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) - { - TextureBrush brush = (TextureBrush)obj; - info.AddValue("Image",brush.Image); - info.AddValue("Transform", brush.Transform); - info.AddValue("WrapMode", brush.WrapMode); - } - /// - /// Populates the object using the information in the SerializationInfo - /// - /// The object to populate. - /// The information to populate the object. - /// The source from which the object is deserialized. - /// The surrogate selector where the search for a compatible surrogate begins. - /// - public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) - { - TextureBrush brush = new TextureBrush((Image)info.GetValue("Image", typeof(Image))); - brush.Transform = (Matrix)info.GetValue("Transform", typeof(Matrix)); - brush.WrapMode = (WrapMode)info.GetValue("WrapMode", typeof(WrapMode)); - return null; - } - } + /// + /// Populates the object using the information in the SerializationInfo + /// + /// The object to populate. + /// The information to populate the object. + /// The source from which the object is deserialized. + /// The surrogate selector where the search for a compatible surrogate begins. + /// + public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + { + float[] elements = (float[]) info.GetValue("Elements", typeof(float[])); + Matrix mat = new Matrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); + return null; + } + } - /// - /// Surrogate class used for serializing System.Drawing.Pen - /// - public class PenSurrogate : ISerializationSurrogate - { - /// - /// Populates the provided SerializationInfo with the data needed to serialize the object. - /// - /// The object to serialize. - /// The SerializationInfo to populate with data. - /// The destination for this serialization. - public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) - { - System.Drawing.Pen pen = (System.Drawing.Pen)obj; - if (pen.Color != Color.Empty) - { - info.AddValue("Color", pen.Color); + /// + /// Surrogate class used for serializing System.Drawing.Pen + /// + public class PenSurrogate : ISerializationSurrogate + { + /// + /// Populates the provided SerializationInfo with the data needed to serialize the object. + /// + /// The object to serialize. + /// The SerializationInfo to populate with data. + /// The destination for this serialization. + public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) + { + Pen pen = (Pen) obj; + if (pen.Color != Color.Empty) + { + info.AddValue("Color", pen.Color); + info.AddValue("Width", pen.Width); + info.AddValue("Alignment", pen.Alignment); + //info.AddValue("Brush", pen.Brush); + info.AddValue("CompoundArray", pen.CompoundArray); + //Todo: + //info.AddValue("CustomEndCap", pen.CustomEndCap); + //info.AddValue("CustomStartCap", pen.CustomStartCap); + //pen.DashCap; + //pen.DashOffset; + info.AddValue("DashPattern", pen.DashPattern); + //pen.DashStyle; + //pen.EndCap; + //pen.LineJoin; + //pen.MiterLimit; + //pen.PenType; + //pen.StartCap; + info.AddValue("Transform", pen.Transform); + } + } - info.AddValue("Width", pen.Width); - info.AddValue("Alignment", pen.Alignment); - //info.AddValue("Brush", pen.Brush); - info.AddValue("CompoundArray", pen.CompoundArray); - //Todo: - //info.AddValue("CustomEndCap", pen.CustomEndCap); - //info.AddValue("CustomStartCap", pen.CustomStartCap); - //pen.DashCap; - //pen.DashOffset; - info.AddValue("DashPattern", pen.DashPattern); - //pen.DashStyle; - //pen.EndCap; - //pen.LineJoin; - //pen.MiterLimit; - //pen.PenType; - //pen.StartCap; - info.AddValue("Transform", pen.Transform); - } - } + /// + /// Populates the object using the information in the SerializationInfo + /// + /// The object to populate. + /// The information to populate the object. + /// The source from which the object is deserialized. + /// The surrogate selector where the search for a compatible surrogate begins. + /// + public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + { + Pen pen = new Pen((Color) info.GetValue("Color", typeof(Color))); + pen.Width = (float) info.GetValue("Width", typeof(float)); + pen.Alignment = (PenAlignment) info.GetValue("Alignment", typeof(PenAlignment)); + //pen.Brush = (Brush)info.GetValue("Brush", typeof(Brush)); + try + { + pen.CompoundArray = (float[]) info.GetValue("CompoundArray", typeof(float[])); + } + catch {} + //pen.CustomEndCap = (CustomLineCap)info.GetValue("CustomEndCap", typeof(CustomLineCap)); + //pen.CustomStartCap = (CustomLineCap)info.GetValue("CustomStartCap", typeof(CustomLineCap)); + pen.DashPattern = (float[]) info.GetValue("DashPattern", typeof(float[])); + try + { + pen.Transform = (Matrix) info.GetValue("Transform", typeof(Matrix)); + } + catch {} + return null; + } + } - /// - /// Populates the object using the information in the SerializationInfo - /// - /// The object to populate. - /// The information to populate the object. - /// The source from which the object is deserialized. - /// The surrogate selector where the search for a compatible surrogate begins. - /// - public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) - { - Pen pen = new Pen((Color)info.GetValue("Color", typeof(Color))); - pen.Width = (float)info.GetValue("Width", typeof(float)); - pen.Alignment = (PenAlignment)info.GetValue("Alignment", typeof(PenAlignment)); - //pen.Brush = (Brush)info.GetValue("Brush", typeof(Brush)); - try { pen.CompoundArray = (float[])info.GetValue("CompoundArray", typeof(float[])); } catch { } - //pen.CustomEndCap = (CustomLineCap)info.GetValue("CustomEndCap", typeof(CustomLineCap)); - //pen.CustomStartCap = (CustomLineCap)info.GetValue("CustomStartCap", typeof(CustomLineCap)); - pen.DashPattern = (float[])info.GetValue("DashPattern", typeof(float[])); - try { pen.Transform = (Matrix)info.GetValue("Transform", typeof(Matrix)); } catch { } - return null; - } - } + /// + /// Surrogate class used for serializing System.Drawing.SolidBrush + /// + public class SolidBrushSurrogate : ISerializationSurrogate + { + /// + /// Populates the provided SerializationInfo with the data needed to serialize the object. + /// + /// The object to serialize. + /// The SerializationInfo to populate with data. + /// The destination for this serialization. + public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) + { + SolidBrush brush = (SolidBrush) obj; + info.AddValue("Color", brush.Color); + } - /// - /// Surrogate class used for serializing System.Drawing.Drawing2D.Matrix - /// - public class MatrixSurrogate : ISerializationSurrogate - { - /// - /// Populates the provided SerializationInfo with the data needed to serialize the object. - /// - /// The object to serialize. - /// The SerializationInfo to populate with data. - /// The destination for this serialization. - public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) - { - Matrix mat = (Matrix)obj; - info.AddValue("Elements", mat.Elements); - } - /// - /// Populates the object using the information in the SerializationInfo - /// - /// The object to populate. - /// The information to populate the object. - /// The source from which the object is deserialized. - /// The surrogate selector where the search for a compatible surrogate begins. - /// - public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) - { - float[] elements = (float[])info.GetValue("Elements", typeof(float[])); - Matrix mat = new Matrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); - return null; - } - } - } + /// + /// Populates the object using the information in the SerializationInfo + /// + /// The object to populate. + /// The information to populate the object. + /// The source from which the object is deserialized. + /// The surrogate selector where the search for a compatible surrogate begins. + /// + public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + { + SolidBrush brush = new SolidBrush((Color) info.GetValue("Color", typeof(Color))); + return null; + } + } + + /// + /// Surrogate class used for serializing System.Drawing.TextureBrush + /// + public class TextureBrushSurrogate : ISerializationSurrogate + { + /// + /// Populates the provided SerializationInfo with the data needed to serialize the object. + /// + /// The object to serialize. + /// The SerializationInfo to populate with data. + /// The destination for this serialization. + public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) + { + TextureBrush brush = (TextureBrush) obj; + info.AddValue("Image", brush.Image); + info.AddValue("Transform", brush.Transform); + info.AddValue("WrapMode", brush.WrapMode); + } + + /// + /// Populates the object using the information in the SerializationInfo + /// + /// The object to populate. + /// The information to populate the object. + /// The source from which the object is deserialized. + /// The surrogate selector where the search for a compatible surrogate begins. + /// + public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) + { + TextureBrush brush = new TextureBrush((Image) info.GetValue("Image", typeof(Image))); + brush.Transform = (Matrix) info.GetValue("Transform", typeof(Matrix)); + brush.WrapMode = (WrapMode) info.GetValue("WrapMode", typeof(WrapMode)); + return null; + } + } + } } \ No newline at end of file