当前位置: 首页>>代码示例>>C#>>正文


C# XmlAttributeOverrides.Add方法代码示例

本文整理汇总了C#中System.Xml.Serialization.XmlAttributeOverrides.Add方法的典型用法代码示例。如果您正苦于以下问题:C# XmlAttributeOverrides.Add方法的具体用法?C# XmlAttributeOverrides.Add怎么用?C# XmlAttributeOverrides.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Serialization.XmlAttributeOverrides的用法示例。


在下文中一共展示了XmlAttributeOverrides.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadStateFromFile

		public static PersistentVM LoadStateFromFile(string filePath)
		{
			PersistentVM persistentVM;
			if (File.Exists(filePath))
			{
				XmlAttributeOverrides xmlAttributeOverride = new XmlAttributeOverrides();
				XmlAttributes xmlAttribute = new XmlAttributes();
				xmlAttribute.XmlIgnore = true;
				xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "MediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(OSVirtualHardDisk), "MediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(OSVirtualHardDisk), "SourceImageName", xmlAttribute);
				Type[] typeArray = new Type[1];
				typeArray[0] = typeof(NetworkConfigurationSet);
				XmlSerializer xmlSerializer = new XmlSerializer(typeof(PersistentVM), xmlAttributeOverride, typeArray, null, null);
				using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
				{
					persistentVM = xmlSerializer.Deserialize(fileStream) as PersistentVM;
				}
				return persistentVM;
			}
			else
			{
				throw new ArgumentException("The file to load the role does not exist", "filePath");
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:26,代码来源:PersistentVMHelper.cs

示例2: LoadStateFromFile

        public static PersistentVM LoadStateFromFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(Resources.MissingPersistentVMFile, "filePath");
            }

            XmlAttributeOverrides overrides = new XmlAttributeOverrides();
            XmlAttributes ignoreAttrib = new XmlAttributes();
            ignoreAttrib.XmlIgnore = true;
            overrides.Add(typeof(DataVirtualHardDisk), "MediaLink", ignoreAttrib);
            overrides.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", ignoreAttrib);
            overrides.Add(typeof(OSVirtualHardDisk), "MediaLink", ignoreAttrib);
            overrides.Add(typeof(OSVirtualHardDisk), "SourceImageName", ignoreAttrib);

            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PersistentVM), overrides, new Type[] { typeof(NetworkConfigurationSet) }, null, null);

            PersistentVM role = null;
            
            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                role = serializer.Deserialize(stream) as PersistentVM;
            }

            return role;
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:26,代码来源:PersistentVMHelper.cs

示例3: Load

        public static ModuleConfiguration Load(string fileName, List<Type> displayList, List<Type> deviceList,
                                               List<Type> sourceList, List<Type> mappingList)
        {
            string configurationSchemaFile = Path.ChangeExtension(fileName, "xsd");
            try
            {
                XmlAttributeOverrides ovr = new XmlAttributeOverrides();

                XmlAttributes attrsDevice = new XmlAttributes();
                XmlAttributes attrsSource = new XmlAttributes();
                XmlAttributes attrsDisplay = new XmlAttributes();
                XmlAttributes attrsMapping = new XmlAttributes();

                attrsMapping.XmlArrayItems.Add(new XmlArrayItemAttribute(typeof (Mapping)));

                foreach (Type type in sourceList)
                    attrsSource.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in deviceList)
                    attrsDevice.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in displayList)
                    attrsDisplay.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in mappingList)
                    attrsMapping.XmlArrayItems.Add(new XmlArrayItemAttribute(type));

                ovr.Add(typeof (ModuleConfiguration), "DeviceList", attrsDevice);
                ovr.Add(typeof (ModuleConfiguration), "SourceList", attrsSource);
                ovr.Add(typeof (ModuleConfiguration), "DisplayList", attrsDisplay);
                ovr.Add(typeof (DisplayType), "MappingList", attrsMapping);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationType = ValidationType.Schema;
                settings.Schemas.Add("urn:configuration-schema", configurationSchemaFile);
                // Проводим валидацию, отдельно от десереализации, потому-что если вместе то валится
                using (XmlReader reader = XmlReader.Create(fileName, settings))
                    while (reader.Read())
                    {
                    }
                // Проводим десереализации без валидации, потому-что если вместе то валится
                XmlSerializer serializer = new XmlSerializer(typeof (ModuleConfiguration), ovr);
                using (XmlReader reader = XmlReader.Create(fileName))
                    return (ModuleConfiguration) serializer.Deserialize(reader);
            }
            catch (FileNotFoundException ex)
            {
                throw new ModuleConfigurationException(ex.FileName);
            }
            catch (XmlSchemaException ex)
            {
                throw new ModuleConfigurationException(new Uri(ex.SourceUri).AbsolutePath, ex);    //configurationSchemaFile
            }
            catch (XmlException ex)
            {
                throw new ModuleConfigurationException(new Uri(ex.SourceUri).AbsolutePath, ex);
            }
        }
开发者ID:AlexSneg,项目名称:VIRD-1.0,代码行数:55,代码来源:ModuleConfigurationExtenstion.cs

示例4: InitializeSerializer

        private void InitializeSerializer()
        {
            XmlAttributes attrs = new XmlAttributes();
            XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
            attrOverrides.Add(typeof(string), "File", attrs);
            attrOverrides.Add(typeof(List<string>), "Columns", attrs);
            attrOverrides.Add(typeof(List<List<string>>), "Rows", attrs);

            m_compositionXmlSerializer = new XmlSerializer(typeof(List<List<string>>), attrOverrides);

            m_mapSerializer = new TmxMapSerializer.Serializer.TmxMapSerializer();
        }
开发者ID:GoodAI,项目名称:BrainSimulator,代码行数:12,代码来源:Form1.cs

示例5: ButtonSendErrorReport_Click

        private async void ButtonSendErrorReport_Click(object sender, RoutedEventArgs e)
        {
            var ex = Error.ToExceptionless();
            ex.SetUserDescription(string.Empty, NoteTextBox.Text);
            ex.AddObject(HurricaneSettings.Instance.Config, "HurricaneSettings", null, null, true);

            if (HurricaneSettings.Instance.IsLoaded)
            {
                using (var sw = new StringWriter())
                {
                    XmlAttributeOverrides overrides = new XmlAttributeOverrides(); //DONT serialize the passwords and send them to me!
                    XmlAttributes attribs = new XmlAttributes {XmlIgnore = true};
                    attribs.XmlElements.Add(new XmlElementAttribute("Passwords"));
                    overrides.Add(typeof(ConfigSettings), "Passwords", attribs);

                    var xmls = new XmlSerializer(typeof(ConfigSettings), overrides);
                    xmls.Serialize(sw, HurricaneSettings.Instance.Config);

                    var doc = new XmlDocument();
                    doc.LoadXml(sw.ToString());
                    ex.SetProperty("HurricaneSettings", JsonConvert.SerializeXmlNode(doc));
                }
            }

            ex.Submit();
            ((Button)sender).IsEnabled = false;
            StatusProgressBar.IsIndeterminate = true;
            await ExceptionlessClient.Default.ProcessQueueAsync();
            StatusProgressBar.IsIndeterminate = false;
            Application.Current.Shutdown();
        }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:31,代码来源:ReportExceptionWindow.xaml.cs

示例6: button1_Click

        //SerialSample4\form1.cs
        private void button1_Click(object sender, System.EventArgs e)
        {
            //create the XmlAttributes boject
              XmlAttributes attrs=new XmlAttributes();
              //add the types of the objects that will be serialized
              attrs.XmlElements.Add(new XmlElementAttribute("Book",typeof(BookProduct)));
              attrs.XmlElements.Add(new XmlElementAttribute("Product",typeof(Product)));
              XmlAttributeOverrides attrOver=new XmlAttributeOverrides();
              //add to the attributes collection
              attrOver.Add(typeof(Inventory),"InventoryItems",attrs);
              //create the Product and Book objects
              Product newProd=new Product();
              BookProduct newBook=new BookProduct();

              newProd.ProductID=100;
              newProd.ProductName="Product Thing";
              newProd.SupplierID=10;

              newBook.ProductID=101;
              newBook.ProductName="How to Use Your New Product Thing";
              newBook.SupplierID=10;
              newBook.ISBN="123456789";

              Product[] addProd={newProd,newBook};

              Inventory inv=new Inventory();
              inv.InventoryItems=addProd;
              TextWriter tr=new StreamWriter("..\\..\\..\\inventory.xml");
              XmlSerializer sr=new XmlSerializer(typeof(Inventory),attrOver);

              sr.Serialize(tr,inv);
              tr.Close();
            MessageBox.Show("Serialized!");
        }
开发者ID:alannet,项目名称:example,代码行数:35,代码来源:Form1.cs

示例7: getRequestContent

        public static byte[] getRequestContent(string doctype, string root, Type type, object obj)
        {
            var xattribs = new XmlAttributes();
            var xroot = new XmlRootAttribute(root);
            xattribs.XmlRoot = xroot;
            var xoverrides = new XmlAttributeOverrides();
            //... have to use XmlAttributeOverrides because .NET insists on the object name as root element name otherwise ([XmlRoot(..)] has no effect)
            xoverrides.Add(type, xattribs);

            XmlSerializer serializer = new XmlSerializer(type, xoverrides);
            StringWriter sw = new StringWriter();
            XmlWriterSettings wsettings = new XmlWriterSettings();
            wsettings.OmitXmlDeclaration = false;
            wsettings.Encoding = new UTF8Encoding();
            XmlWriter xw = XmlWriter.Create(sw, wsettings);
            xw.WriteProcessingInstruction("xml", "version='1.0' standalone='no'");
            //... have to write header by hand (OmitXmlDeclaration=false has no effect)
            xw.WriteDocType(root, null, doctype + ".sfrm", null);

            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            //... trick to avoid printing of xmlns:xsi xmlns:xsd attributes of the root element

            serializer.Serialize(xw, obj, ns);
            return sw.ToArray();
        }
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:26,代码来源:Serializer.cs

示例8: Serialize

        /// <summary>
        /// Serializes an object into an XML document
        /// </summary>
        /// <param name="obj">object to serialize</param>
        /// <param name="rootAttribute">root attribute to use</param>
        /// <param name="namespacePrefixes">namespace prefixes</param>
        /// <returns>a string that contains the XML document</returns>
        public static string Serialize(object obj, XmlRootAttribute rootAttribute, params XmlQualifiedName[] namespacePrefixes)
        {
            if (obj == null)
            {
                return null;
            }

            using (var textWriter = new StringWriterUTF8())
            {
                var type = obj.GetType();
                var xmlAttributeOverrides = new XmlAttributeOverrides();
                if (rootAttribute != null)
                {
                    var xmlAttributes = new XmlAttributes();
                    xmlAttributes.XmlRoot = rootAttribute;
                    xmlAttributeOverrides.Add(type, xmlAttributes);
                }
                using (var xmWriter = XmlWriter.Create(textWriter, new XmlWriterSettings() { OmitXmlDeclaration = true }))
                {
                    var namespaces = new XmlSerializerNamespaces();
                    if (namespacePrefixes != null)
                    {
                        foreach (var ns in namespacePrefixes)
                        {
                            namespaces.Add(ns.Name, ns.Namespace);
                        }
                    }
                    new XmlSerializer(type, xmlAttributeOverrides).Serialize(xmWriter, obj, namespaces);
                }
                return textWriter.ToString();
            }
        }
开发者ID:kakone,项目名称:SSDP.Portable,代码行数:39,代码来源:XmlSerializerUtility.cs

示例9: getRequestContent

        public byte[] getRequestContent( string doctype, string root, Type type, object obj)
        {
            XmlSerializer serializer = null;
            if (root == null)
            {
                //... root element will be the object type name
                serializer = new XmlSerializer(type);
            }
            else
            {
                //... root element set explicitely
                var xattribs = new XmlAttributes();
                var xroot = new XmlRootAttribute(root);
                xattribs.XmlRoot = xroot;
                var xoverrides = new XmlAttributeOverrides();
                xoverrides.Add(type, xattribs);
                serializer = new XmlSerializer(type, xoverrides);
            }
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = false;
            settings.OmitXmlDeclaration = false;
            settings.Encoding = new UTF8Encoding(false/*no BOM*/, true/*throw if input illegal*/);

            XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
            xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlNameSpace.Add("noNamespaceSchemaLocation", m_schemadir + "/" + doctype + "." + m_schemaext);

            StringWriter sw = new StringWriter();
            XmlWriter xw = XmlWriter.Create( sw, settings);
            xw.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");

            serializer.Serialize(xw, obj, xmlNameSpace);

            return settings.Encoding.GetBytes( sw.ToString());
        }
开发者ID:ProjectTegano,项目名称:Tegano,代码行数:35,代码来源:Serializer.cs

示例10: Create

        public static XmlAttributeOverrides Create(Type objectType)
        {
            XmlAttributeOverrides xOver = null;

            if (!table.TryGetValue(objectType, out xOver))
            {
                // Create XmlAttributeOverrides object.
                xOver = new XmlAttributeOverrides();

                /* Create an XmlTypeAttribute and change the name of the XML type. */
                XmlTypeAttribute xType = new XmlTypeAttribute();
                xType.TypeName = objectType.Name;

                // Set the XmlTypeAttribute to the XmlType property.
                XmlAttributes attrs = new XmlAttributes();
                attrs.XmlType = xType;

                /* Add the XmlAttributes to the XmlAttributeOverrides,
                   specifying the member to override. */
                xOver.Add(objectType, attrs);

                table.MergeSafe(objectType, xOver);
            }

            return xOver;
        }
开发者ID:lucaslra,项目名称:SPM,代码行数:26,代码来源:XmlAttributeOverridesFactory.cs

示例11: SameObjectWithRootAttribute

		public void SameObjectWithRootAttribute()
		{
			XmlAttributeOverrides ov = new XmlAttributeOverrides();
			XmlAttributes atts = new XmlAttributes();
			atts.XmlRoot = new XmlRootAttribute("myRoot");
			ov.Add(typeof(SerializeMe), atts);

			ThumbprintHelpers.SameThumbprint(ov, ov);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:9,代码来源:XmlAttributeOverridesThumbprinterTester.cs

示例12: GetConfig

        public static Config GetConfig(string configFilePath)
        {
            using (var fs = new FileStream(configFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                XmlAttributes attributes = new XmlAttributes { XmlIgnore = true };
                XmlAttributeOverrides overrides = new XmlAttributeOverrides();
                overrides.Add(typeof(AlertSourceIncident), "CustomFields", attributes);

                // Microsoft.AzureAd.Icm.Types.TenantIdentifier cannot be serialized because it does not have a parameterless constructor.
                overrides.Add(typeof(AlertSourceIncident), "ServiceResponsible", attributes);
                overrides.Add(typeof(AlertSourceIncident), "ImpactedServices", attributes);

                var serializer = new XmlSerializer(typeof(Config), overrides);
                var configObject = (Config)serializer.Deserialize(fs);
                configObject.Name = Path.GetFileNameWithoutExtension(configFilePath);
                return configObject;
            }
        }
开发者ID:strince,项目名称:mail2bug,代码行数:18,代码来源:Config.cs

示例13: SaveStateToFile

        public static void SaveStateToFile(PersistentVM role, string filePath)
        {
            if (role == null)
            {
                throw new ArgumentNullException("role", Resources.MissingPersistentVMRole);
            }
            
            XmlAttributeOverrides overrides = new XmlAttributeOverrides();
            XmlAttributes ignoreAttrib = new XmlAttributes();
            ignoreAttrib.XmlIgnore = true;
            overrides.Add(typeof(DataVirtualHardDisk), "MediaLink", ignoreAttrib);
            overrides.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", ignoreAttrib);
            overrides.Add(typeof(OSVirtualHardDisk), "MediaLink", ignoreAttrib);

            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PersistentVM), overrides, new Type[] { typeof(NetworkConfigurationSet) }, null, null);
            using (TextWriter writer = new StreamWriter(filePath))
            {
                serializer.Serialize(writer, role);
            }
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:20,代码来源:PersistentVMHelper.cs

示例14: WriteTo

        public void WriteTo(TextWriter tw)
        {
            XmlAttributeOverrides overrides = new XmlAttributeOverrides();
            XmlAttributes attrs = new XmlAttributes {XmlIgnore = true};

            overrides.Add(Object.GetType(), "Id", attributes: attrs);

            XmlSerializer xs = new XmlSerializer(Object.GetType(), overrides);

            xs.Serialize(tw, Object);
        }
开发者ID:driverpt,项目名称:PI-1112SV,代码行数:11,代码来源:XmlDoc.cs

示例15: SerializeToXml

        private void SerializeToXml(TransportMessage transportMessage, MemoryStream stream)
        {
            var overrides = new XmlAttributeOverrides();
            var attrs = new XmlAttributes { XmlIgnore = true };

            overrides.Add(typeof(TransportMessage), "Messages", attrs);
            overrides.Add(typeof(TransportMessage), "Address", attrs);
            overrides.Add(typeof(TransportMessage), "ReplyToAddress", attrs);
            overrides.Add(typeof(TransportMessage), "Headers", attrs);
            overrides.Add(typeof(TransportMessage), "Body", attrs);
            var xs = new XmlSerializer(typeof(TransportMessage), overrides);

            var doc = new XmlDocument();

            using (var tempstream = new MemoryStream())
            {
                xs.Serialize(tempstream, transportMessage);
                tempstream.Position = 0;

                doc.Load(tempstream);
            }

            var data = transportMessage.Body != null ? Encoding.UTF8.GetString(transportMessage.Body) : string.Empty;

            var bodyElement = doc.CreateElement("Body");
            bodyElement.AppendChild(doc.CreateCDataSection(data));
            doc.DocumentElement.AppendChild(bodyElement);

            var headers = new SerializableDictionary<string, string>(transportMessage.Headers);

            var headerElement = doc.CreateElement("Headers");
            headerElement.InnerXml = headers.GetXml();
            doc.DocumentElement.AppendChild(headerElement);

            var replyToAddressElement = doc.CreateElement("ReplyToAddress");
            replyToAddressElement.InnerText = transportMessage.ReplyToAddress.ToString();
            doc.DocumentElement.AppendChild(replyToAddressElement);

            doc.Save(stream);
            stream.Position = 0;
        }
开发者ID:rosieks,项目名称:NServiceBus-Contrib,代码行数:41,代码来源:OracleAqsMessageSender.cs


注:本文中的System.Xml.Serialization.XmlAttributeOverrides.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。