Example #1
0
 private static Hashtable GetTypesHashtable(XmlAttributeOverrides overrides)
 {
     return(GetHashtable(overrides, "types"));
 }
Example #2
0
        private bool CreateCSProject <T>(IEnumerable <T> objects, XMLConfig config)
        {
            bool success = true;

            Project doc = objects.ToList()[0] as Project;

            if (doc == null)
            {
                BH.Engine.Reflection.Compute.RecordError("The CSProject schema requires a full system to be provided as a single push operation.");
                return(false);
            }

            try
            {
                System.Reflection.PropertyInfo[] bhomProperties = typeof(BHoMObject).GetProperties();
                XmlAttributeOverrides            overrides      = new XmlAttributeOverrides();

                foreach (System.Reflection.PropertyInfo pi in bhomProperties)
                {
                    overrides.Add(typeof(BHoMObject), pi.Name, new XmlAttributes {
                        XmlIgnore = true
                    });
                }

                XmlSerializerNamespaces xns = new XmlSerializerNamespaces();
                xns.Add("", "");

                List <string> xmlParts = new List <string>();

                xmlParts.Add("<Project ToolsVersion=\"" + doc.ToolsVersion + "\" DefaultTarget=\"" + doc.DefaultTargets + "\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");

                StringWriter textWriter = new StringWriter();

                XmlSerializer szer = new XmlSerializer(typeof(BH.oM.XML.CSProject.Import), overrides);
                for (int x = 0; x < doc.Imports.Count - 1; x++)
                {
                    szer.Serialize(textWriter, doc.Imports[x], xns);
                    xmlParts.Add(textWriter.ToString());
                    textWriter = new StringWriter(); //To be safe
                }

                szer = new XmlSerializer(typeof(BH.oM.XML.CSProject.PropertyGroup), overrides);
                for (int x = 0; x < doc.PropertyGroups.Count - 1; x++)
                {
                    szer.Serialize(textWriter, doc.PropertyGroups[x], xns);
                    xmlParts.Add(textWriter.ToString());
                    textWriter = new StringWriter(); //To be safe
                }

                szer = new XmlSerializer(typeof(BH.oM.XML.CSProject.ItemGroup), overrides);
                foreach (var i in doc.ItemGroups)
                {
                    szer.Serialize(textWriter, i, xns);
                    xmlParts.Add(textWriter.ToString());
                    textWriter = new StringWriter();
                }

                szer = new XmlSerializer(typeof(BH.oM.XML.CSProject.Import), overrides);
                szer.Serialize(textWriter, doc.Imports.Last(), xns);
                xmlParts.Add(textWriter.ToString());
                textWriter = new StringWriter();

                szer = new XmlSerializer(typeof(BH.oM.XML.CSProject.PropertyGroup), overrides);
                szer.Serialize(textWriter, doc.PropertyGroups.Last(), xns);
                xmlParts.Add(textWriter.ToString());
                textWriter = new StringWriter();

                xmlParts.Add("</Project>");

                StreamWriter sw = new StreamWriter(_fileSettings.GetFullFileName());

                xmlParts = xmlParts.Select(x => Regex.Replace(x, @"<\?xml version=""1.0"" encoding=""utf-[0-9]*""\?>\r\n", "")).ToList();
                xmlParts = xmlParts.Select(x => x.Replace("q1:", "")).ToList();

                sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

                foreach (string s in xmlParts)
                {
                    sw.WriteLine(s);
                }

                sw.Close();
            }
            catch (Exception e)
            {
                BH.Engine.Reflection.Compute.RecordError(e.ToString());
                success = false;
            }

            return(success);
        }
Example #3
0
        public static ShaderWindowSettings LoadConfiguration(out DialogResult result)
        {
            if (!File.Exists(ShaderManager.DefaultConfigurationFile))
            {
                result = DialogResult.OK;
                return(new ShaderWindowSettings());
            }

            var olderVersion = false;

            using (var reader = XmlReader.Create(ShaderManager.DefaultConfigurationFile))
            {
                olderVersion = reader.ReadToDescendant("ShaderConfiguration") &&
                               reader.AttributeCount == 0;
            }

            if (olderVersion)
            {
                result = MessageBox.Show(
                    Resources.ConfigurationFileUpgrade_Message,
                    Resources.ConfigurationFileUpgrade_Caption,
                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }

                var overrides        = new XmlAttributeOverrides();
                var shaderAttributes = new XmlAttributes();
                var materialElement  = new XmlArrayItemAttribute();
                materialElement.ElementName = "ShaderConfiguration";
                materialElement.Type        = typeof(MaterialConfiguration);
                shaderAttributes.XmlArrayItems.Add(materialElement);
                overrides.Add(typeof(ShaderWindowSettings), "Shaders", shaderAttributes);

                var bufferBindingAttributes = new XmlAttributes();
                var textureBindingElement   = new XmlArrayItemAttribute();
                textureBindingElement.ElementName = "TextureBindingConfiguration";
                textureBindingElement.Type        = typeof(TextureBindingConfiguration);
                bufferBindingAttributes.XmlArray  = new XmlArrayAttribute("TextureBindings");
                bufferBindingAttributes.XmlArrayItems.Add(textureBindingElement);
                overrides.Add(typeof(ShaderConfiguration), "BufferBindings", bufferBindingAttributes);

                ShaderWindowSettings configuration;
                var serializer = new XmlSerializer(typeof(ShaderWindowSettings), overrides);
                using (var reader = XmlReader.Create(ShaderManager.DefaultConfigurationFile))
                {
                    configuration = (ShaderWindowSettings)serializer.Deserialize(reader);
                }

                if (result == DialogResult.Yes)
                {
                    ShaderManager.SaveConfiguration(configuration);
                }
                else
                {
                    return(configuration);
                }
            }

            result = DialogResult.OK;
            try { return(ShaderManager.LoadConfiguration()); }
            catch
            {
                result = DialogResult.Cancel;
                throw;
            }
        }
Example #4
0
        // Write ProjectList member variables (XMin, XMax, YMin, Ymax, UseGeographicMap)
        // and ProjectLocation member variables (ID, DefinitionFile, X, Y, Description, Default)
        // as attributes into XML, so XamlReader can work happily.
        //
        static XmlAttributeOverrides CreateProjectListOverrides()
        {
            XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

            // add root element namespace
            attrOverrides.Add(typeof(ProjectList), new XmlAttributes()
            {
                XmlRoot = new XmlRootAttribute()
                {
                    ElementName = "ProjectList",
                    Namespace   = "clr-namespace:iS3.Core;assembly=iS3.Core"
                }
            });

            // write ProjectList member variables as attributes
            attrOverrides.Add(typeof(ProjectList), "XMax", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("XMax")
            });
            attrOverrides.Add(typeof(ProjectList), "XMin", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("XMin")
            });
            attrOverrides.Add(typeof(ProjectList), "YMax", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("YMax")
            });
            attrOverrides.Add(typeof(ProjectList), "YMin", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("YMin")
            });
            attrOverrides.Add(typeof(ProjectList), "UseGeographicMap", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("UseGeographicMap")
            });

            // write ProjectLocation member variables as attributes
            attrOverrides.Add(typeof(ProjectLocation), "ID", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("ID")
            });
            attrOverrides.Add(typeof(ProjectLocation), "DefinitionFile", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("DefinitionFile")
            });
            attrOverrides.Add(typeof(ProjectLocation), "X", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("X")
            });
            attrOverrides.Add(typeof(ProjectLocation), "Y", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("Y")
            });
            attrOverrides.Add(typeof(ProjectLocation), "Description", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("Description")
            });
            attrOverrides.Add(typeof(ProjectLocation), "Default", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("Default")
            });

            return(attrOverrides);
        }
Example #5
0
        /// <summary>
        /// Loops to the inheritance chain of an object, takes xml attributes from base
        /// objects and applies the overrides to the derived object
        /// </summary>
        /// <param name="baseType"></param>
        /// <param name="derivedType"></param>
        /// <param name="overrides"></param>
        public static void AddAttributeOverrides(Type baseType, Type derivedType, XmlAttributeOverrides overrides)
        {
            //loop, starting with derived type
            Type type = derivedType;

            do
            {
                //override attributes detected the next basetype
                type = type.BaseType;
                if (type == null)
                {
                    break;
                }
                PropertyInfo[] props = baseType.GetProperties();
                foreach (PropertyInfo pi in props)
                {
                    //do not override attribute again if it already has override
                    XmlAttributes overrideAttributes = overrides[derivedType, pi.Name];
                    if (overrideAttributes == null)
                    {
                        Object[] attributes = pi.GetCustomAttributes(true);

                        foreach (Object a in attributes)
                        {
                            XmlAttributes attrs = new XmlAttributes();
                            if (a is XmlAttributeAttribute)
                            {
                                attrs.XmlAttribute = a as XmlAttributeAttribute;
                            }
                            else if (a is XmlElementAttribute)
                            {
                                attrs.XmlElements.Add(a as XmlElementAttribute);
                            }
                            else if (a is XmlIgnoreAttribute)
                            {
                                attrs.XmlIgnore = true;
                            }
                            else if (a is XmlArrayAttribute)
                            {
                                attrs.XmlArray = a as XmlArrayAttribute;
                            }
                            else if (a is XmlArrayItemAttribute)
                            {
                                attrs.XmlArrayItems.Add(a as XmlArrayItemAttribute);
                            }
                            else
                            {
                                continue;
                            }


                            bool exist = false; // first check if attribute does not exist

                            // iterate over all properties because there can be property which hides type of the base class
                            PropertyInfo[] properties = derivedType.GetProperties();
                            foreach (PropertyInfo pi2 in properties)
                            {
                                if (pi2.Name == pi.Name && pi2.Name != "Item")
                                {
                                    Object[] attrs2 = derivedType.GetProperty(pi2.Name, pi2.PropertyType).GetCustomAttributes(false);
                                    foreach (Object a2 in attrs2)
                                    {
                                        if (a2.Equals(a))
                                        {
                                            exist = true;
                                        }
                                    }
                                }
                            }

                            if (!exist) // override
                            {
                                overrides.Add(derivedType, pi.Name, attrs);
                            }
                        }
                    }
                }
            } while (!type.Equals(baseType));
        }
 public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides, string defaultNamespace);
Example #7
0
        /// <summary>
        /// 将一个对象序列化为XML字符串
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="encoding">编码方式</param>
        /// <returns>序列化产生的XML字符串</returns>
        public static string XmlSerialize(object o, Encoding encoding, XmlSerializerNamespaces namespaces, XmlAttributeOverrides xmlAttributeOverrides = null)
        {
            string value = null;

            using (MemoryStream stream = new MemoryStream())
            {
                XmlSerializeInternal(stream, o, encoding, namespaces, xmlAttributeOverrides);

                stream.Position = 0;
                using (StreamReader reader = new StreamReader(stream, encoding))
                {
                    value = reader.ReadToEnd();
                    reader.Close();
                }
                stream.Close();
            }
            return(value);
        }
 /// <summary>
 /// Create a new instance of a XmlSerializationProvider that uses an underlying
 /// XmlSerializer that is created with the supplied arguments.
 /// </summary>
 public XmlSerializationProvider(Type type, XmlAttributeOverrides overrides)
     : base(type, new XmlSerializer(type, overrides))
 {
 }
 /// <summary>
 /// Create a new instance of a XmlSerializationProvider that uses an underlying
 /// XmlSerializer that is created with the supplied arguments.
 /// </summary>
 public XmlSerializationProvider(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location)
     : base(type, new XmlSerializer(type, overrides, extraTypes, root, defaultNamespace, location))
 {
 }
Example #10
0
        public PresetDropdown(IServiceProvider ServiceProvider, string OwnerName, T DefaultPreset, XmlAttributeOverrides XmlAttributeOverrides)
        {
            InitializeComponent();
            Services       = ServiceProvider;
            this.OwnerName = OwnerName;

            defaultPreset = current = DefaultPreset;

            xao = XmlAttributeOverrides;

            this.SetStyle(
                ControlStyles.FixedHeight
                | ControlStyles.Selectable
                | ControlStyles.ResizeRedraw,
                true);

            PopulateDropdown();
        }
Example #11
0
        /// <summary>
        /// Загружает содержимое файла типа .bib
        /// в список изданий
        /// </summary>
        private void btnLoad_Click(object sender, EventArgs e)
        {
            Stream         fileStream;
            OpenFileDialog openFileDialog = new OpenFileDialog();
            string         filePath;
            string         fileContent = string.Empty;

            openFileDialog.Filter           = "bib files (*.bib)|*.bib";
            openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filePath   = openFileDialog.FileName;
                fileStream = openFileDialog.OpenFile();

                using (StreamReader streamReader = new StreamReader(fileStream))
                {
                    fileContent = streamReader.ReadToEnd();
                }

                gridEditions.Rows.Clear();
                editions.Clear();

                XElement xRoot = XElement.Parse(
                    fileContent,
                    LoadOptions.SetLineInfo);

                var      allNodes         = xRoot.DescendantNodesAndSelf();
                var      nodesToSerialize = new List <XElement>();
                string[] arrEditionTypes  = Enum.GetNames(typeof(EditionTypes));

                foreach (var node in allNodes)
                {
                    if (node is XElement)
                    {
                        string name = ((XElement)node).Name.LocalName;
                        if (arrEditionTypes.Contains(name))
                        {
                            nodesToSerialize.Add((XElement)node);
                        }
                    }
                }

                XmlSerializer reader      = null;
                Type          editionType = null;
                IEdition      edition     = null;
                Assembly      assembly    = typeof(IEdition).Assembly;
                string        typeName;
                List <Person> authors          = new List <Person>();
                string        exceptionMessage = string.Empty;

                XmlAttributes attrs = new XmlAttributes();
                attrs.XmlIgnore = true;
                attrs.XmlElements.Add(
                    new XmlElementAttribute()
                {
                    ElementName = "Authors"
                });

                XmlAttributeOverrides attrOverrides =
                    new XmlAttributeOverrides();

                assembly.GetTypes().ToList().
                Where(x => x.IsClass &&
                      x.GetInterfaces().Contains(typeof(IEdition))).
                ToList().ForEach(type =>
                {
                    attrOverrides.Add(type, "Authors", attrs);
                });

                foreach (var xml in nodesToSerialize)
                {
                    try
                    {
                        typeName    = "Model." + xml.Name.LocalName;
                        editionType = assembly.GetType(typeName);
                        reader      = new XmlSerializer(editionType, attrOverrides);
                        authors     = new List <Person>();

                        using (TextReader stream = new StringReader(xml.ToString()))
                        {
                            edition = (IEdition)(Convert.ChangeType(
                                                     reader.Deserialize(stream), editionType));
                        }
                        using (TextReader stream = new StringReader(xml.ToString()))
                        {
                            XmlReaderSettings settings = new XmlReaderSettings
                            {
                                IgnoreComments   = true,
                                IgnoreWhitespace = true
                            };

                            using (XmlReader xmlReader =
                                       XmlReader.Create(stream, settings))
                            {
                                while (!xmlReader.EOF)
                                {
                                    if (xmlReader.Name != "Person")
                                    {
                                        xmlReader.ReadToFollowing("Person");
                                    }

                                    if (!xmlReader.EOF)
                                    {
                                        XElement person = (XElement)XNode.ReadFrom(xmlReader);
                                        Person   author = new Person
                                        {
                                            FirstName  = (string)person.Element("FirstName"),
                                            SecondName = (string)person.Element("SecondName"),
                                            Patronymic = (string)person.Element("Patronymic")
                                        };
                                        authors.Add(author);
                                    }
                                }

                                editionType.GetProperty("Authors").SetValue(
                                    Convert.ChangeType(edition, editionType),
                                    authors);

                                editions.Add(edition);
                                gridEditions.Rows.Add(edition.StandartName);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        exceptionMessage += "Error while loading file \n";
                    }
                }

                gridEditions.Update();
                gridEditions.Refresh();

                if (!string.IsNullOrEmpty(exceptionMessage))
                {
                    MessageBox.Show(
                        "Error while parsing " + exceptionMessage,
                        "Loading Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
                SetButtonsEnable();
            }
        }
Example #12
0
        /// <summary>
        /// Loads the GUI Scene from disk
        /// </summary>
        /// <returns></returns>
        public static GUIScene Load(string filename, XmlAttributeOverrides overrides)
        {
            GUIScene   scene = null;
            FileStream fs    = null;

            try
            {
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                XmlSerializer serializer = new XmlSerializer(typeof(GUIScene), overrides);
                serializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);
                serializer.UnknownElement   += new XmlElementEventHandler(serializer_UnknownElement);
                scene = serializer.Deserialize(fs) as GUIScene;

                foreach (GUIView view in scene.Views)
                {
                    view.Scene = scene;
                    view.PostImport();

                    // Once all the references and whatnot have been fixed up, set the
                    // sceneView's current state to be the first frame of the first channel.
                    // (effectively frame 0 of "OnActivate")
                    view.CurrentAnimationIndex = 0;
                    if (view.CurrentAnimation != null)
                    {
                        view.CurrentAnimation.Frame = 0;
                        view.CurrentAnimation.UpdateAnimations();
                    }
                }

                // TODO - perform any specific fixups here.

                // Set the scene's version to current, as it is assumed that after
                // all fixups and stuff it is now "correct"
                scene.Version = Otter.Properties.Settings.Default.SceneVersion;

                GUIProjectScene sceneEntry = GUIProject.CurrentProject.GetSceneEntry(filename);
                if (sceneEntry != null)
                {
                    scene.ID = sceneEntry.ID;
                }

                List <string> availableCustomControls = new List <string>();

                // Now cycle through our list of control descriptors and see if we're missing any plugins
                XmlAttributes attributes = overrides[typeof(Otter.UI.GUIControl), "Controls"];
                foreach (XmlArrayItemAttribute xmlAttr in attributes.XmlArrayItems)
                {
                    Type type = xmlAttr.Type;

                    // Found a custom GUIControl.  Ensure that the "ControlAttribute" is present
                    System.Attribute attribute = System.Attribute.GetCustomAttribute(type, typeof(Plugins.ControlAttribute));
                    if (attribute != null)
                    {
                        Otter.Plugins.ControlAttribute  controlAttribute  = (Otter.Plugins.ControlAttribute)attribute;
                        Otter.Plugins.ControlDescriptor controlDescriptor = controlAttribute.GetDescriptor();

                        if (controlDescriptor != null)
                        {
                            availableCustomControls.Add(type.FullName);
                        }
                    }
                }

                // We have a list of available plugins, now store the plugins we're missing (if any)
                foreach (string customControlName in scene.CustomControlsUsed)
                {
                    if (!availableCustomControls.Contains(customControlName))
                    {
                        scene.MissingCustomControls.Add(customControlName);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            return(scene);
        }
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location, System.Security.Policy.Evidence evidence)
 {
 }
 public XmlSerializer(Type type, XmlAttributeOverrides overrides)
 {
 }
Example #15
0
File: test.cs Project: mono/gert
	public override string ToString ()
	{
		string result = string.Empty;

		using (MemoryStream stream = new MemoryStream ()) {
			using (StreamReader sr = new StreamReader (stream)) {
				XmlTextWriter writer = null;

				try {
					writer = new XmlTextWriter (stream, System.Text.Encoding.UTF8);
					XmlAttributes attrs = new XmlAttributes ();
					XmlElementAttribute attr = new XmlElementAttribute ();
					attr.ElementName = "UnknownItemSerializer";
					attr.Type = typeof (UnknownItemSerializer);
					attrs.XmlElements.Add (attr);
					XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides ();
					attrOverrides.Add (typeof (TestClass), "Item", attrs);

					XmlSerializer serializer = new XmlSerializer (this.GetType (), attrOverrides);
					serializer.Serialize (writer, this);

					stream.Position = 0;
					result = sr.ReadToEnd ();
				} finally {
					if (writer != null)
						writer.Close ();
				}
			}
		}

		return result;
	}
Example #16
0
 /// <summary>
 /// Creates a new instance of the XMLResult class.
 /// </summary>
 /// <param name="objectToSerialize">The object to serialize to XML.</param>
 /// <param name="xmlAttributeOverrides"></param>
 public XmlResult(object objectToSerialize, XmlAttributeOverrides xmlAttributeOverrides)
 {
     _objectToSerialize    = objectToSerialize;
     _xmlAttribueOverrides = xmlAttributeOverrides;
 }
 public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides)
 {
 }
Example #18
0
 /// <summary> Initializes a new instance that can serialize objects of type <typeparamref name="T"/> into XML documents, and deserialize XML documents into instances of type <typeparamref name="T"/>. Each object to be serialized can itself contain instances of classes, which this overload can override with other classes. </summary>
 public XmlSerializer(XmlAttributeOverrides overrides)
     : base(typeof(T), overrides)
 {
 }
Example #19
0
        /// <summary>
        /// 将一个对象按指定的编码序列化到指定流中
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="o"></param>
        /// <param name="encoding"></param>
        public static void XmlSerializeInternal(Stream stream, object o, Encoding encoding, XmlSerializerNamespaces namespaces, XmlAttributeOverrides xmlAttributeOverrides = null)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            XmlSerializer serializer = null;

            if (xmlAttributeOverrides == null)
            {
                serializer = new XmlSerializer(o.GetType());
            }
            else
            {
                serializer = new XmlSerializer(o.GetType(), xmlAttributeOverrides);
            }

            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent       = true,
                NewLineChars = "\r\n",
                Encoding     = encoding,
                IndentChars  = "    "
            };

            using (XmlWriter writer = XmlWriter.Create(stream, settings))
            {
                if (namespaces != null)
                {
                    serializer.Serialize(writer, o, namespaces);
                }
                else
                {
                    serializer.Serialize(writer, o);
                }
                writer.Close();
            }
        }
Example #20
0
 /// <summary> Initializes a new instance that can serialize objects of type <typeparamref name="T"/> into XML document instances, and deserialize XML document instances into instances of type <typeparamref name="T"/>. Each instance to be serialized can itself contain instances of classes, which this overload overrides with other classes. This overload also specifies the default namespace for all the XML elements and the class to use as the XML root element, and the location of the types. </summary>
 public XmlSerializer(XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location)
     : base(typeof(T), overrides, extraTypes, root, defaultNamespace, location)
 {
 }
Example #21
0
        /// <summary>
        /// 将一个对象按XML序列化的方式写入到一个文件
        /// </summary>
        /// <param name="o">要序列化的对象</param>
        /// <param name="path">保存文件路径</param>
        /// <param name="encoding">编码方式</param>
        public static void XmlSerializeToFile(object o, string path, Encoding encoding, XmlSerializerNamespaces namespaces, XmlAttributeOverrides xmlAttributeOverrides = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            using (FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                XmlSerializeInternal(file, o, encoding, namespaces, xmlAttributeOverrides);
                file.Close();
            }
        }
 public static XmlAttributeOverrides AddXmlArrayItemTypes(this XmlAttributeOverrides overrides, Type declaringType, Type itemType, IEnumerable <Type> derivedTypes)
 {
     return(overrides.AddXmlArrayItemTypes(declaringType, itemType, derivedTypes, new HashSet <Type>()));
 }
Example #23
0
        //public static string Serialize<T>(object obj)
        //{
        //    StringWriter sw = new StringWriter();
        //    XmlSerializer xs = new XmlSerializer(typeof(T));
        //    xs.Serialize(sw, obj);
        //    return sw.ToString();
        //}

        //public static T Deserialize<T>(string xml)
        //{
        //    StringReader sr = new StringReader(xml);
        //    XmlSerializer xs = new XmlSerializer(typeof(T));
        //    return (T)xs.Deserialize(sr);
        //}

        public static string ObjectToXML(object input, bool isWss40)
        {
            XmlAttributeOverrides xmlOverrides = new XmlAttributeOverrides();

            return(ObjectToXML(input, isWss40, null));
        }
Example #24
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace) :
     this(type, overrides, extraTypes, root, defaultNamespace, null)
 {
 }
Example #25
0
        private bool FillRecord(object rec, Tuple <long, XElement> pair)
        {
            long     lineNo;
            XElement node;

            lineNo = pair.Item1;
            node   = pair.Item2;

            fXElements  = null;
            fieldValue  = null;
            fieldConfig = null;
            pi          = null;
            xpn         = node.CreateNavigator(Configuration.NamespaceManager.NameTable);
            ToDictionary(node);

            foreach (KeyValuePair <string, ChoXmlRecordFieldConfiguration> kvp in Configuration.RecordFieldConfigurationsDict)
            {
                fieldValue  = null;
                fieldConfig = kvp.Value;
                if (Configuration.PIDict != null)
                {
                    Configuration.PIDict.TryGetValue(kvp.Key, out pi);
                }

                if (fieldConfig.XPath == "text()")
                {
                    if (Configuration.GetNameWithNamespace(node.Name) == fieldConfig.FieldName)
                    {
                        object value = node;
                        if (!RaiseBeforeRecordFieldLoad(rec, pair.Item1, kvp.Key, ref value))
                        {
                            continue;
                        }
                        if (fieldConfig.ValueConverter != null)
                        {
                            value = fieldConfig.ValueConverter(value);
                        }

                        fieldValue = value is XElement ? node.Value : value;
                    }
                    else if (Configuration.ColumnCountStrict)
                    {
                        throw new ChoParserException("Missing '{0}' xml node.".FormatString(fieldConfig.FieldName));
                    }
                }
                else
                {
                    if (/*!fieldConfig.UseCache && */ !xDict.ContainsKey(fieldConfig.FieldName))
                    {
                        xNodes.Clear();
                        foreach (XPathNavigator z in xpn.Select(fieldConfig.XPath, Configuration.NamespaceManager))
                        {
                            xNodes.Add(z.UnderlyingObject);
                        }

                        object value = xNodes;
                        if (!RaiseBeforeRecordFieldLoad(rec, pair.Item1, kvp.Key, ref value))
                        {
                            continue;
                        }

                        if (fieldConfig.ValueConverter != null)
                        {
                            fieldValue = fieldConfig.ValueConverter(value);
                        }
                        else
                        {
                            //object[] xNodes = ((IEnumerable)node.XPathEvaluate(fieldConfig.XPath, Configuration.NamespaceManager)).OfType<object>().ToArray();
                            //continue;
                            XAttribute fXAttribute = xNodes.OfType <XAttribute>().FirstOrDefault();
                            if (fXAttribute != null)
                            {
                                fieldValue = fXAttribute.Value;
                            }
                            else
                            {
                                fXElements = xNodes.OfType <XElement>().ToArray();
                                if (fXElements != null)
                                {
                                    if (Configuration.IsDynamicObject)
                                    {
                                        if (fieldConfig.IsArray != null && fieldConfig.IsArray.Value)
                                        {
                                            List <object> list = new List <object>();
                                            foreach (var ele in fXElements)
                                            {
                                                if (fieldConfig.FieldType.IsSimple())
                                                {
                                                    list.Add(ChoConvert.ConvertTo(ele.Value, fieldConfig.FieldType.GetItemType()));
                                                }
                                                else
                                                {
                                                    list.Add(ele.GetOuterXml().ToObjectFromXml(fieldConfig.FieldType.GetItemType()));
                                                }
                                            }
                                            fieldValue = list.ToArray();
                                        }
                                        else
                                        {
                                            if (fieldConfig.FieldType == typeof(string) || fieldConfig.FieldType.IsSimple())
                                            {
                                                XElement fXElement = fXElements.FirstOrDefault();
                                                if (fXElement != null)
                                                {
                                                    fieldValue = fXElement.Value;
                                                }
                                            }
                                            else
                                            {
                                                XmlAttributeOverrides overrides = null;
                                                var xattribs = new XmlAttributes();
                                                var xroot    = new XmlRootAttribute(fieldConfig.FieldName);
                                                xattribs.XmlRoot = xroot;
                                                overrides        = new XmlAttributeOverrides();
                                                overrides.Add(fieldConfig.FieldType, xattribs);

                                                XElement fXElement = fXElements.FirstOrDefault();
                                                if (fXElement != null)
                                                {
                                                    fieldValue = fXElement.GetOuterXml().ToObjectFromXml(fieldConfig.FieldType, overrides);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        XmlAttributeOverrides overrides = null;
                                        var xattribs = new XmlAttributes();
                                        var xroot    = new XmlRootAttribute(fieldConfig.FieldName);
                                        xattribs.XmlRoot = xroot;
                                        overrides        = new XmlAttributeOverrides();
                                        overrides.Add(fieldConfig.FieldType, xattribs);

                                        XElement fXElement = fXElements.FirstOrDefault();
                                        if (fXElement != null)
                                        {
                                            fieldValue = fXElement.GetOuterXml().ToObjectFromXml(fieldConfig.FieldType, overrides);
                                        }
                                    }
                                }
                                else if (Configuration.ColumnCountStrict)
                                {
                                    throw new ChoParserException("Missing '{0}' xml node.".FormatString(fieldConfig.FieldName));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (xDict[fieldConfig.FieldName].Count == 1)
                        {
                            fieldValue = xDict[fieldConfig.FieldName][0];
                        }
                        else
                        {
                            fieldValue = xDict[fieldConfig.FieldName];
                        }

                        if (!RaiseBeforeRecordFieldLoad(rec, pair.Item1, kvp.Key, ref fieldValue))
                        {
                            continue;
                        }

                        if (fieldConfig.ValueConverter != null)
                        {
                            fieldValue = fieldConfig.ValueConverter(fieldValue);
                        }
                    }
                }

                if (Configuration.IsDynamicObject)
                {
                    if (kvp.Value.FieldType == null)
                    {
                        kvp.Value.FieldType = fieldValue is ICollection ? typeof(string[]) : DiscoverFieldType(fieldValue as string);
                    }
                }
                else
                {
                    if (pi != null)
                    {
                        kvp.Value.FieldType = pi.PropertyType;
                    }
                    else
                    {
                        kvp.Value.FieldType = typeof(string);
                    }
                }

                if (fieldValue is string)
                {
                    fieldValue = CleanFieldValue(fieldConfig, kvp.Value.FieldType, fieldValue as string);
                }

                try
                {
                    bool ignoreFieldValue = fieldConfig.IgnoreFieldValue(fieldValue);
                    if (ignoreFieldValue)
                    {
                        fieldValue = fieldConfig.IsDefaultValueSpecified ? fieldConfig.DefaultValue : null;
                    }

                    if (Configuration.IsDynamicObject)
                    {
                        var dict = rec as IDictionary <string, Object>;

                        if (!fieldConfig.IsArray.CastTo <bool>())
                        {
                            dict.ConvertNSetMemberValue(kvp.Key, kvp.Value, ref fieldValue, Configuration.Culture);
                        }
                        else
                        {
                            dict[kvp.Key] = fieldValue;
                        }

                        if ((Configuration.ObjectValidationMode & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
                        {
                            dict.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                        }
                    }
                    else
                    {
                        if (pi != null)
                        {
                            rec.ConvertNSetMemberValue(kvp.Key, kvp.Value, ref fieldValue, Configuration.Culture);
                        }
                        else
                        {
                            throw new ChoMissingRecordFieldException("Missing '{0}' property in {1} type.".FormatString(kvp.Key, ChoType.GetTypeName(rec)));
                        }

                        if ((Configuration.ObjectValidationMode & ChoObjectValidationMode.MemberLevel) == ChoObjectValidationMode.MemberLevel)
                        {
                            rec.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                        }
                    }

                    if (!RaiseAfterRecordFieldLoad(rec, pair.Item1, kvp.Key, fieldValue))
                    {
                        return(false);
                    }
                }
                catch (ChoParserException)
                {
                    throw;
                }
                catch (ChoMissingRecordFieldException)
                {
                    if (Configuration.ThrowAndStopOnMissingField)
                    {
                        throw;
                    }
                }
                catch (Exception ex)
                {
                    ChoETLFramework.HandleException(ex);

                    if (fieldConfig.ErrorMode == ChoErrorMode.ThrowAndStop)
                    {
                        throw;
                    }

                    try
                    {
                        if (Configuration.IsDynamicObject)
                        {
                            var dict = rec as IDictionary <string, Object>;

                            if (dict.SetFallbackValue(kvp.Key, kvp.Value, Configuration.Culture, ref fieldValue))
                            {
                                dict.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                            }
                            else if (dict.SetDefaultValue(kvp.Key, kvp.Value, Configuration.Culture))
                            {
                                dict.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                            }
                            else
                            {
                                throw new ChoReaderException($"Failed to parse '{fieldValue}' value for '{fieldConfig.FieldName}' field.", ex);
                            }
                        }
                        else if (pi != null)
                        {
                            if (rec.SetFallbackValue(kvp.Key, kvp.Value, Configuration.Culture))
                            {
                                rec.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                            }
                            else if (rec.SetDefaultValue(kvp.Key, kvp.Value, Configuration.Culture))
                            {
                                rec.DoMemberLevelValidation(kvp.Key, kvp.Value, Configuration.ObjectValidationMode);
                            }
                            else
                            {
                                throw new ChoReaderException($"Failed to parse '{fieldValue}' value for '{fieldConfig.FieldName}' field.", ex);
                            }
                        }
                        else
                        {
                            throw new ChoReaderException($"Failed to parse '{fieldValue}' value for '{fieldConfig.FieldName}' field.", ex);
                        }
                    }
                    catch (Exception innerEx)
                    {
                        if (ex == innerEx.InnerException)
                        {
                            if (fieldConfig.ErrorMode == ChoErrorMode.IgnoreAndContinue)
                            {
                                continue;
                            }
                            else
                            {
                                if (!RaiseRecordFieldLoadError(rec, pair.Item1, kvp.Key, fieldValue, ex))
                                {
                                    throw new ChoReaderException($"Failed to parse '{fieldValue}' value for '{fieldConfig.FieldName}' field.", ex);
                                }
                            }
                        }
                        else
                        {
                            throw new ChoReaderException("Failed to assign '{0}' fallback value to '{1}' field.".FormatString(fieldValue, fieldConfig.FieldName), innerEx);
                        }
                    }
                }
            }

            return(true);
        }
Example #26
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer4"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides) : this(type, overrides, Array.Empty <Type>(), null, null, null)
 {
 }
Example #27
0
 private void Serialize(object o, XmlAttributeOverrides ao)
 {
     SetUpWriter();
     xs = new XmlSerializer(o.GetType(), ao);
     xs.Serialize(xtw, o);
 }
Example #28
0
 public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides) : this(attributeOverrides, null)
 {
 }
Example #29
0
 /// <summary>
 /// Gets a thumbprint (signature)
 /// for the content of the XmlAttributeOverrides
 /// </summary>
 /// <param name="overrides"></param>
 /// <returns></returns>
 public static string GetThumbprint(XmlAttributeOverrides overrides)
 {
     return(GetClassThumbprint(overrides));
 }
        //static XmlSerializerNamespaces _xmlSerializerNamespaces;

        static TemplatePackageManifest()
        {
            var v10Overrides = new XmlAttributeOverrides();

            var v10DependencyEnumMap = new Dictionary <string, string>()
            {
                { "NoDependency", "NoDependency" },
                { "PrimaryCmpFile", "BaseCmpFile" },
                { "SharedCmpFile", "PointedToCmpFile" },
                { "InsertedTemplate", "TemplateInsert" },
                { "InsertedClause", "ClauseInsert" },
                { "InsertedClauseLibrary", "ClauseLibraryInsert" },
                { "InsertedImage", "ImageInsert" },
                { "InterviewImage", "InterviewImage" },
                { "VariableInsertedTemplate", "VariableTemplateInsert" },
                { "VariableInsertedImage", "VariableImageInsert" },
                { "MissingVariable", "MissingVariable" },
                { "MissingFile", "MissingFile" },
                { "AssembledTemplate", "Assemble" },
                { "PublisherMapFile", "PublisherMapFile" },
                { "UserMapFile", "UserMapFile" }
            };

            foreach (var kv in v10DependencyEnumMap)
            {
                v10Overrides.Add(typeof(DependencyType), kv.Value, new XmlAttributes()
                {
                    XmlEnum = new XmlEnumAttribute(kv.Key)
                });
            }

            v10Overrides.Add(typeof(Dependency), "FileName", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("target")
            });
            v10Overrides.Add(typeof(TemplateInfo), "FileName", new XmlAttributes()
            {
                XmlAttribute = new XmlAttributeAttribute("name")
            });
            var attributes = new XmlAttributes()
            {
                XmlArray = new XmlArrayAttribute("serverFiles")
            };

            attributes.XmlArrayItems.Add(new XmlArrayItemAttribute("file"));
            v10Overrides.Add(typeof(TemplateInfo), "GeneratedHDFiles", attributes);

            _xmlSerializer   = new XmlSerializer(typeof(TemplatePackageManifest), PackageNamespace);
            _xmlSerializer10 = new XmlSerializer(typeof(TemplatePackageManifest), v10Overrides, null, null, PackageNamespace10);

            //_xmlSerializerNamespaces = new XmlSerializerNamespaces();
            //_xmlSerializerNamespaces.Add(string.Empty, string.Empty);

            /*
             * TemplatePackageManifest manifest = new TemplatePackageManifest();
             * var main = manifest.MainTemplate = new TemplateInfo();
             * main.FileName = "myfilename.rtf";
             * main.EffectiveComponentFile = "mycomponentfile.cmp";
             * string xml;
             * using (var sw = new StringWriter())
             * {
             *      _xmlSerializer10.Serialize(sw, manifest);
             *      xml = sw.ToString();
             * }
             */
        }
Example #31
0
 private XmlModelBuilder(XmlAttributeOverrides attributeOverrides, IEnumerable <string> ignoredMembersByDefault)
 {
     overrides      = attributeOverrides;
     ignoredMembers = new HashSet <string>(ignoredMembersByDefault);
 }
Example #32
0
        static void TestWmts()
        {
            XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

            XmlAttributes       ddsAttrs  = new XmlAttributes();
            XmlElementAttribute layerAttr = new XmlElementAttribute
            {
                ElementName = "Layer",
                Type        = typeof(LayerType)
            };

            ddsAttrs.XmlElements.Add(layerAttr);
            attrOverrides.Add(typeof(ContentsBaseType), "DatasetDescriptionSummary", ddsAttrs);

            #region ServiceIdentification
            LanguageStringType[] titles = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "Web Map Tile Service"
                }
            };
            LanguageStringType[] abstracts = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "Service that contrains the map access interface to some TileMatrixSets"
                }
            };
            LanguageStringType[] keyword1 = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "tile"
                }
            };
            KeywordsType keywordsType1 = new KeywordsType()
            {
                Keyword = keyword1
            };
            LanguageStringType[] keyword2 = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = "map"
                }
            };
            KeywordsType keywordsType2 = new KeywordsType()
            {
                Keyword = keyword2
            };
            KeywordsType[] keywords = new KeywordsType[]
            {
                keywordsType1, keywordsType2
            };
            CodeType serviceType = new CodeType()
            {
                Value = "OGC WMTS"
            };
            string[] serviceTypeVersion = new string[]
            {
                "1.0.0"
            };
            string   fees = "none";
            string[] accessConstraints = new string[]
            {
                "none"
            };
            ServiceIdentification serviceIdentification = new ServiceIdentification()
            {
                Title              = titles,
                Abstract           = abstracts,
                Keywords           = keywords,
                ServiceType        = serviceType,
                ServiceTypeVersion = serviceTypeVersion,
                Fees = fees,
                AccessConstraints = accessConstraints
            };
            #endregion
            string href = "http://123";
            #region ServiceProvider
            string             poroviderName    = "SharpMapServer";
            OnlineResourceType providerSiteType = new OnlineResourceType()
            {
                href = href
            };
            string[]      voices     = new string[] { "0000-00000000" };
            string[]      facsimiles = new string[] { "0001-00000001" };
            TelephoneType phone      = new TelephoneType()
            {
                Voice     = voices,
                Facsimile = facsimiles
            };
            string[]    deliveryPoints        = new string[] { "jinjiang" };
            string      city                  = "chengdu";
            string      administrativeArea    = "sichuan";
            string      country               = "china";
            string[]    electronicMailAddress = new string[] { "*****@*****.**" };
            string      postalCode            = "123456";
            AddressType address               = new AddressType()
            {
                DeliveryPoint         = deliveryPoints,
                City                  = city,
                AdministrativeArea    = administrativeArea,
                Country               = country,
                ElectronicMailAddress = electronicMailAddress,
                PostalCode            = postalCode
            };
            ContactType contactInfo = new ContactType()
            {
                Phone   = phone,
                Address = address
            };
            string individualName = "lc";
            string positionName   = "Senior Software Engineer";
            ResponsiblePartySubsetType serviceContact = new ResponsiblePartySubsetType()
            {
                IndividualName = individualName,
                PositionName   = positionName,
                ContactInfo    = contactInfo
            };
            ServiceProvider serviceProvider = new ServiceProvider()
            {
                ProviderName   = poroviderName,
                ProviderSite   = providerSiteType,
                ServiceContact = serviceContact
            };
            #endregion

            #region OperationsMetadata
            Operation   getCapabilitiesOperation = CapabilitiesHelper.GetOperation(href, "GetCapabilities");
            Operation   getTileOperation         = CapabilitiesHelper.GetOperation(href, "GetTile");
            Operation   getFeatureinfoOperation  = CapabilitiesHelper.GetOperation(href, "GetFeatureinfo");
            Operation[] operations = new Operation[]
            {
                getCapabilitiesOperation,
                getTileOperation,
                getFeatureinfoOperation
            };
            OperationsMetadata operationsMetadata = new OperationsMetadata()
            {
                Operation = operations
            };
            #endregion
            Capabilities capabilities = new Capabilities()
            {
                ServiceIdentification = serviceIdentification,
                ServiceProvider       = serviceProvider,
                OperationsMetadata    = operationsMetadata
            };
            IWmtsService wmts1Service = OgcServiceHelper.GetOgcService("WMTS", "1.0.0") as IWmtsService;
            wmts1Service.AddContent(capabilities, @"E:\LC\数据\双流\2014年遥感影像.img");

            List <object> objs = new List <object>();
            capabilities.Themes = new Themes[]
            {
                new Themes()
                {
                    Theme = new Theme[]
                    {
                        new Theme()
                        {
                            Identifier = new CodeType()
                            {
                                Value = "123"
                            }
                        }
                    }
                }
            };
            objs.Add(capabilities);
            StringBuilder sb = new StringBuilder();
            using (TextWriter tw = new StringWriter(sb))
            {
                foreach (var item in objs)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var serializer = new XmlSerializer(item.GetType(), attrOverrides);
                    serializer.Serialize(tw, item);
                    var val = sb.ToString();
                    File.WriteAllText("123.xml", val);
                    sb.Clear();
                }
            }
        }
 // Methods
 public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace)
 {
 }
    public void SerializeObject(string studentFilename, string bookFilename)
    {
        XmlSerializer mySerializer;
        TextWriter    writer;

        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlAttributeOverrides =
            new XmlAttributeOverrides();
        XmlAttributes myXmlAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to
         * the XmlAttribute property of the XmlAttributes object.*/
        XmlAttributeAttribute myXmlAttributeAttribute =
            new XmlAttributeAttribute();

        myXmlAttributeAttribute.AttributeName = "Name";
        myXmlAttributes.XmlAttribute          = myXmlAttributeAttribute;


        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlAttributeOverrides.Add(typeof(Student), "StudentName",
                                    myXmlAttributes);

        // Create the XmlSerializer.
        mySerializer = new  XmlSerializer(typeof(Student),
                                          myXmlAttributeOverrides);

        writer = new StreamWriter(studentFilename);

        // Create an instance of the class that will be serialized.
        Student myStudent = new Student();

        // Set the Name property, which will be generated as an XML attribute.
        myStudent.StudentName   = "James";
        myStudent.StudentNumber = 1;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myStudent);
        writer.Close();

        // Create the XmlAttributeOverrides and XmlAttributes objects.
        XmlAttributeOverrides myXmlBookAttributeOverrides =
            new XmlAttributeOverrides();
        XmlAttributes myXmlBookAttributes = new XmlAttributes();

        /* Create an XmlAttributeAttribute set it to
         * the XmlAttribute property of the XmlAttributes object.*/
        XmlAttributeAttribute myXmlBookAttributeAttribute =
            new XmlAttributeAttribute("Name");

        myXmlBookAttributes.XmlAttribute = myXmlBookAttributeAttribute;


        // Add to the XmlAttributeOverrides. Specify the member name.
        myXmlBookAttributeOverrides.Add(typeof(Book), "BookName",
                                        myXmlBookAttributes);

        // Create the XmlSerializer.
        mySerializer = new  XmlSerializer(typeof(Book),
                                          myXmlBookAttributeOverrides);

        writer = new StreamWriter(bookFilename);

        // Create an instance of the class that will be serialized.
        Book myBook = new Book();

        // Set the Name property, which will be generated as an XML attribute.
        myBook.BookName   = ".NET";
        myBook.BookNumber = 10;
        // Serialize the class, and close the TextWriter.
        mySerializer.Serialize(writer, myBook);
        writer.Close();
    }
 public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location, System.Security.Policy.Evidence evidence)
 {
 }
 public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides);