• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Serialization.XmlAttributeOverrides类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



XmlAttributeOverrides类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlAttributeOverrides类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: SameEmptyObjectTwice

		public void SameEmptyObjectTwice()
		{
			// the same object should most certainly
			// result in the same signature, even when it's empty
			XmlAttributeOverrides ov = new XmlAttributeOverrides();
			ThumbprintHelpers.SameThumbprint(ov, ov);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:7,代码来源:XmlAttributeOverridesThumbprinterTester.cs


示例6: 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


示例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: 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


示例9: OnCreateXmlSerializer

 protected virtual void OnCreateXmlSerializer(XmlAttributeOverrides overrides, List<Type> additionalTypes, List<Type> additionalControls)
 {
     if (GetType().Assembly != typeof(IWindowlessControl).Assembly)
     {
         AddAssemblyControlsToList(GetType().Assembly, additionalControls);
     }
 }
开发者ID:koush,项目名称:WindowlessControls,代码行数:7,代码来源:SerializableControl.cs


示例10: GetOverridesSignature

		/// <summary>
		/// Creates a signature for the passed in XmlAttributeOverrides
		/// </summary>
		/// <param name="overrides"></param>
		/// <returns>An instance indpendent signature of the XmlAttributeOverrides</returns>
		public static string GetOverridesSignature(XmlAttributeOverrides overrides)
		{
			// GetHashCode looks at something other than the content
			// of XmlOverrideAttributes and comes up with different
			// hash values for two instances that would produce
			// the same XML is the were applied to the XmlSerializer.
			// Therefore I need to do something more intelligent
			// to normalize the content of XmlAttributeOverrides
			// or extract a thumbpront that only accounts for the
			// attributes in XmlAttributeOverrides.

			// The main problems is that 
			// I can only access the hashtables that store the 
			// overriding attributes through reflection, i.e.
			// I can't run the XmlSerializerCache in a partially
			// trusted security context.
			//
			// Also, the extra computation to create a purely
			// content-based thumbprint not offset the savings.
			// 
			// If none if these were an issue I'd simply say:
			// return overrides.GetHashCode().ToString();

			string thumbPrint = null;
			if (null != overrides)
			{
				thumbPrint = XmlAttributeOverridesThumbprinter.GetThumbprint(overrides);
			}
			return thumbPrint;
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:35,代码来源:SignatureExtractor.cs


示例11: DifferentThumbprint

		internal static void DifferentThumbprint(XmlAttributeOverrides ov1, XmlAttributeOverrides ov2)
		{
			string print1 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov1);
			string print2 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov2);

			Assert.IsFalse(print1 == print2);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:7,代码来源:ThumbprintHelpers.cs


示例12: 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


示例13: GetExportedDefinitionsOverrides

        public static XmlAttributeOverrides GetExportedDefinitionsOverrides(XmlAttributeOverrides DefinitionsOverrides)
        {
            var _container = PluginContainer.GetOvalCompositionContainer();

            var testTypes = _container.GetExports<TestType>().Select(exp => exp.Value.GetType());
            var objectTypes = _container.GetExports<ObjectType>().Select(exp => exp.Value.GetType());
            var stateTypes = _container.GetExports<StateType>().Select(exp => exp.Value.GetType());

            XmlAttributes testAttributes = new XmlAttributes();
            foreach (var testType in testTypes)
            {
                var xmlAttrs = (testType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                testAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, testType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "tests", testAttributes);
            XmlAttributes objectAttributes = new XmlAttributes();
            foreach (var objectType in objectTypes)
            {
                var xmlAttrs = (objectType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                objectAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, objectType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "objects", objectAttributes);

            XmlAttributes stateAttributes = new XmlAttributes();
            foreach (var stateType in stateTypes)
            {
                var xmlAttrs = (stateType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                stateAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, stateType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "states", stateAttributes);

            return DefinitionsOverrides;
        }
开发者ID:ywcsz,项目名称:modSIC,代码行数:33,代码来源:oval_definitions.cs


示例14: SerializeToXml

        private static string SerializeToXml(TransportMessage transportMessage)
        {
            var overrides = new XmlAttributeOverrides();
            var attrs = new XmlAttributes {XmlIgnore = true};

            // Exclude non-serializable members
            overrides.Add(typeof (TransportMessage), "Body", attrs);
            overrides.Add(typeof (TransportMessage), "ReplyToAddress", attrs);
            overrides.Add(typeof (TransportMessage), "Headers", attrs);

            var sb = new StringBuilder();
            var xws = new XmlWriterSettings { Encoding = Encoding.Unicode };
            var xw = XmlWriter.Create(sb, xws);
            var xs = new XmlSerializer(typeof (TransportMessage), overrides);
            xs.Serialize(xw, transportMessage);

            var xdoc = XDocument.Parse(sb.ToString());
            var body = new XElement("Body");
            var cdata = new XCData(Encoding.UTF8.GetString(transportMessage.Body));
            body.Add(cdata);
            xdoc.SafeElement("TransportMessage").Add(body);

            sb.Clear();
            var sw = new StringWriter(sb);
            xdoc.Save(sw);

            return sb.ToString();
        }
开发者ID:rmoritz,项目名称:NServiceBus-Contrib,代码行数:28,代码来源:ServiceBrokerMessageSender.cs


示例15: XmlSerializer

 /// <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) {
     XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);
     for (int i = 0; i < extraTypes.Length; i++)
         importer.IncludeType(extraTypes[i]);
     tempAssembly = GenerateTempAssembly(importer.ImportTypeMapping(type, root));
     this.events.sender = this;
 }
开发者ID:ArildF,项目名称:masters,代码行数:11,代码来源:xmlserializer.cs


示例16: TwoDifferentEmptyObjects

		public void TwoDifferentEmptyObjects()
		{
			XmlAttributeOverrides ov1 = new XmlAttributeOverrides();
			XmlAttributeOverrides ov2 = new XmlAttributeOverrides();

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


示例17: Create

 public static XmlSerializer Create(Type type, XmlAttributeOverrides overrides)
 {
     Type realType = GetRealType(type);
     XmlSerializer xs = _factory.CreateSerializer(realType, overrides);
     if (xs == null)
         xs = new XmlSerializer(realType, overrides);
     return xs;
 }
开发者ID:4-Roads,项目名称:FourRoads.Common,代码行数:8,代码来源:XmlInjectedSerilization.cs


示例18: Create

 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Xml.Serialization.XmlSerializer"/> class that can serialize objects of type <see cref="T:System.Object"/> into XML document instances, and deserialize XML document instances into objects of type <see cref="T:System.Object"/>. Each object 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.
 /// </summary>
 /// <param name="type">The type of the object that this <see cref="T:System.Xml.Serialization.XmlSerializer"/> can serialize. </param><param name="overrides">An <see cref="T:System.Xml.Serialization.XmlAttributeOverrides"/> that extends or overrides the behavior of the class specified in the <paramref name="type"/> parameter. </param><param name="extraTypes">A <see cref="T:System.Type"/> array of additional object types to serialize. </param><param name="root">An <see cref="T:System.Xml.Serialization.XmlRootAttribute"/> that defines the XML root element properties. </param><param name="defaultNamespace">The default namespace of all XML elements in the XML document. </param>
 public IXmlSerializer Create(Type type,
                              XmlAttributeOverrides overrides,
                              Type[] extraTypes,
                              XmlRootAttribute root,
                              string defaultNamespace)
 {
     return new XmlSerializerWrap(type, overrides, extraTypes, root, defaultNamespace);
 }
开发者ID:YannBrulhart,项目名称:SystemWrapper-1,代码行数:12,代码来源:XmlSerializerFactory.cs


示例19: SameThumbprint

		internal static void SameThumbprint(XmlAttributeOverrides ov1, XmlAttributeOverrides ov2)
		{
			string print1 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov1);
			string print2 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov2);

			//Console.WriteLine("p1 {0}, p2 {1}", print1, print2);
			Assert.AreEqual(print1, print2);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:8,代码来源:ThumbprintHelpers.cs


示例20: Map

		private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
		{
			XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
			XmlTypeMapping tm = ri.ImportTypeMapping(t);
			//Debug.Print(tm);

			return tm;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:XmlReflectionImporterTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.XmlAttributes类代码示例发布时间:2022-05-26
下一篇:
C# Serialization.TypeScope类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap