ImageCollectionCodeDomSerializer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / ImageCollectionCodeDomSerializer.cs / 1 / ImageCollectionCodeDomSerializer.cs

                            namespace  System.Windows.Forms.Design { 

    using System.Design;
    using System.CodeDom;
    using System.Collections; 
    using System.ComponentModel;
    using System.ComponentModel.Design; 
    using System.Diagnostics; 
    using System.Reflection;
    using System.ComponentModel.Design.Serialization; 
    using System.Collections.Specialized;
    using System.Windows.Forms;

 
    /// 
    ///  
    ///     This serializer serializes string dictionaries. 
    /// 
 
    //
    public class ImageListCodeDomSerializer : CodeDomSerializer {

        ///  
        /// 
        ///     This method takes a CodeDomObject and deserializes into a real object. 
        ///     We don't do anything here. 
        /// 
        public override object Deserialize(IDesignerSerializationManager manager, object codeObject) { 

            //

            if (manager == null || codeObject == null) { 
                throw new ArgumentNullException( manager == null ? "manager" : "codeObject");
            } 
 
            // Find our base class's serializer.
            // 
            CodeDomSerializer serializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer));
            if (serializer == null) {
                Debug.Fail("Unable to find a CodeDom serializer for 'Component'.  Has someone tampered with the serialization providers?");
                return null; 
            }
 
            return serializer.Deserialize(manager, codeObject); 
        }
 
        /// 
        /// 
        ///     Serializes the given object into a CodeDom object.
        ///  
        public override object Serialize(IDesignerSerializationManager manager, object value) {
 
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(ImageList).BaseType, typeof(CodeDomSerializer)); 

            object codeObject = baseSerializer.Serialize(manager, value); 

            ImageList imageList = value as ImageList;
            if (imageList != null) {
                StringCollection imageKeys = imageList.Images.Keys; 

                if (codeObject is CodeStatementCollection) { 
                    CodeExpression imageListObject = GetExpression(manager, value); 
                    if (imageListObject != null) {
                        CodeExpression imageListImagesProperty = new CodePropertyReferenceExpression(imageListObject, "Images"); 

                        if (imageListImagesProperty != null) {
                            for (int i = 0; i < imageKeys.Count; i++) {
                                if ((imageKeys[i] != null) || (imageKeys[i].Length != 0)){ 
                                    CodeMethodInvokeExpression setNameMethodCall = new CodeMethodInvokeExpression(imageListImagesProperty, "SetKeyName",
                                                                                   new CodeExpression [] { 
                                                                                            new CodePrimitiveExpression(i),         // SetKeyName(int, 
                                                                                            new CodePrimitiveExpression(imageKeys[i])        // string);
                                                                                            }); 

                                    ((CodeStatementCollection)codeObject).Add(setNameMethodCall);
                                }
                             } 
                        }
                    } 
                } 
            }
            return codeObject; 

        }
    } // Class ImageListCodeDomSerializer
 } // Namespace System.Windows.Forms.Design 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK