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


C# Serialization.XmlAttributes类代码示例

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


XmlAttributes类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例5: NewXmlAttributes

		public void NewXmlAttributes ()
		{
			// seems not different from Type specified ctor().
			XmlAttributes atts = new XmlAttributes ();
			Assert.IsNull (atts.XmlAnyAttribute, "#1");
			Assert.IsNotNull (atts.XmlAnyElements, "#2");
			Assert.AreEqual (0, atts.XmlAnyElements.Count, "#3");
			Assert.IsNull (atts.XmlArray, "#4");
			Assert.IsNotNull (atts.XmlArrayItems, "#5");
			Assert.AreEqual (0, atts.XmlArrayItems.Count, "#6");
			Assert.IsNull (atts.XmlAttribute, "#7");
			Assert.IsNull (atts.XmlChoiceIdentifier, "#8");
			Assert.IsNotNull (atts.XmlDefaultValue, "#9");
			// DBNull??
			Assert.AreEqual (DBNull.Value, atts.XmlDefaultValue, "#10");
			Assert.IsNotNull (atts.XmlElements, "#11");
			Assert.AreEqual (0, atts.XmlElements.Count, "#12");
			Assert.IsNull (atts.XmlEnum, "#13");
			Assert.IsNotNull (atts.XmlIgnore, "#14");
			Assert.AreEqual (TypeCode.Boolean, atts.XmlIgnore.GetTypeCode (), "#15");
			Assert.AreEqual (false, atts.Xmlns, "#16");
			Assert.IsNull (atts.XmlRoot, "#17");
			Assert.IsNull (atts.XmlText, "#18");
			Assert.IsNull (atts.XmlType, "#19");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:25,代码来源:XmlAttributesTests.cs

示例6: NewXmlAttributes

		public void NewXmlAttributes ()
		{
			// seems not different from Type specified ctor().
			XmlAttributes atts = new XmlAttributes ();
			AssertNull (atts.XmlAnyAttribute);
			AssertNotNull (atts.XmlAnyElements);
			AssertEquals (0, atts.XmlAnyElements.Count);
			AssertNull (atts.XmlArray);
			AssertNotNull (atts.XmlArrayItems);
			AssertEquals (0, atts.XmlArrayItems.Count);
			AssertNull (atts.XmlAttribute);
			AssertNull (atts.XmlChoiceIdentifier);
			AssertNotNull (atts.XmlDefaultValue);
			// DBNull??
			AssertEquals (DBNull.Value, atts.XmlDefaultValue);
			AssertNotNull (atts.XmlElements);
			AssertEquals (0, atts.XmlElements.Count);
			AssertNull (atts.XmlEnum);
			AssertNotNull (atts.XmlIgnore);
			AssertEquals (TypeCode.Boolean, atts.XmlIgnore.GetTypeCode ());
			AssertEquals (false, atts.Xmlns);
			AssertNull (atts.XmlRoot);
			AssertNull (atts.XmlText);
			AssertNull (atts.XmlType);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:25,代码来源:XmlAttributesTests.cs

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

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

示例9: GetInitializers

 internal static object[] GetInitializers(LogicalMethodInfo[] methodInfos)
 {
     if (methodInfos.Length == 0)
     {
         return new object[0];
     }
     WebServiceAttribute attribute = WebServiceReflector.GetAttribute(methodInfos);
     bool serviceDefaultIsEncoded = SoapReflector.ServiceDefaultIsEncoded(WebServiceReflector.GetMostDerivedType(methodInfos));
     XmlReflectionImporter importer = SoapReflector.CreateXmlImporter(attribute.Namespace, serviceDefaultIsEncoded);
     WebMethodReflector.IncludeTypes(methodInfos, importer);
     ArrayList list = new ArrayList();
     bool[] flagArray = new bool[methodInfos.Length];
     for (int i = 0; i < methodInfos.Length; i++)
     {
         LogicalMethodInfo methodInfo = methodInfos[i];
         Type returnType = methodInfo.ReturnType;
         if (IsSupported(returnType) && HttpServerProtocol.AreUrlParametersSupported(methodInfo))
         {
             XmlAttributes attributes = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
             XmlTypeMapping mapping = importer.ImportTypeMapping(returnType, attributes.XmlRoot);
             mapping.SetKey(methodInfo.GetKey() + ":Return");
             list.Add(mapping);
             flagArray[i] = true;
         }
     }
     if (list.Count == 0)
     {
         return new object[0];
     }
     XmlMapping[] mappings = (XmlMapping[]) list.ToArray(typeof(XmlMapping));
     Evidence evidenceForType = GetEvidenceForType(methodInfos[0].DeclaringType);
     TraceMethod caller = Tracing.On ? new TraceMethod(typeof(XmlReturn), "GetInitializers", methodInfos) : null;
     if (Tracing.On)
     {
         Tracing.Enter(Tracing.TraceId("TraceCreateSerializer"), caller, new TraceMethod(typeof(XmlSerializer), "FromMappings", new object[] { mappings, evidenceForType }));
     }
     XmlSerializer[] serializerArray = null;
     if (AppDomain.CurrentDomain.IsHomogenous)
     {
         serializerArray = XmlSerializer.FromMappings(mappings);
     }
     else
     {
         serializerArray = XmlSerializer.FromMappings(mappings, evidenceForType);
     }
     if (Tracing.On)
     {
         Tracing.Exit(Tracing.TraceId("TraceCreateSerializer"), caller);
     }
     object[] objArray = new object[methodInfos.Length];
     int num2 = 0;
     for (int j = 0; j < objArray.Length; j++)
     {
         if (flagArray[j])
         {
             objArray[j] = serializerArray[num2++];
         }
     }
     return objArray;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:60,代码来源:XmlReturn.cs

示例10: Add

		public void Add (Type type, string member, XmlAttributes attributes) 
		{
			if(overrides[GetKey(type, member)] != null)
				throw new Exception("The attributes for the given type and Member already exist in the collection");
			
			overrides.Add(GetKey(type,member), attributes);
		}
开发者ID:nobled,项目名称:mono,代码行数:7,代码来源:XmlAttributeOverrides.cs

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

示例12: ReflectReturn

 internal override bool ReflectReturn()
 {
     MessagePart messagePart = new MessagePart {
         Name = "Body"
     };
     base.ReflectionContext.OutputMessage.Parts.Add(messagePart);
     if (typeof(XmlNode).IsAssignableFrom(base.ReflectionContext.Method.ReturnType))
     {
         MimeContentBinding extension = new MimeContentBinding {
             Type = "text/xml",
             Part = messagePart.Name
         };
         base.ReflectionContext.OperationBinding.Output.Extensions.Add(extension);
     }
     else
     {
         MimeXmlBinding binding2 = new MimeXmlBinding {
             Part = messagePart.Name
         };
         LogicalMethodInfo method = base.ReflectionContext.Method;
         XmlAttributes attributes = new XmlAttributes(method.ReturnTypeCustomAttributeProvider);
         XmlTypeMapping xmlTypeMapping = base.ReflectionContext.ReflectionImporter.ImportTypeMapping(method.ReturnType, attributes.XmlRoot);
         xmlTypeMapping.SetKey(method.GetKey() + ":Return");
         base.ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping);
         messagePart.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace);
         base.ReflectionContext.OperationBinding.Output.Extensions.Add(binding2);
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:MimeXmlReflector.cs

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

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

示例15: ReflectReturn

        internal override bool ReflectReturn() {
            MessagePart part = new MessagePart();
            part.Name = "Body";
            ReflectionContext.OutputMessage.Parts.Add(part);

            if (typeof(XmlNode).IsAssignableFrom(ReflectionContext.Method.ReturnType)) {
                MimeContentBinding mimeContentBinding = new MimeContentBinding();
                mimeContentBinding.Type = "text/xml";
                mimeContentBinding.Part = part.Name;
                ReflectionContext.OperationBinding.Output.Extensions.Add(mimeContentBinding);
            }
            else {
                MimeXmlBinding mimeXmlBinding = new MimeXmlBinding();
                mimeXmlBinding.Part = part.Name;

                LogicalMethodInfo methodInfo = ReflectionContext.Method;
                XmlAttributes a = new XmlAttributes(methodInfo.ReturnTypeCustomAttributeProvider);
                XmlTypeMapping xmlTypeMapping = ReflectionContext.ReflectionImporter.ImportTypeMapping(methodInfo.ReturnType, a.XmlRoot);
                xmlTypeMapping.SetKey(methodInfo.GetKey() + ":Return");
                ReflectionContext.SchemaExporter.ExportTypeMapping(xmlTypeMapping);
                part.Element = new XmlQualifiedName(xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace);
                ReflectionContext.OperationBinding.Output.Extensions.Add(mimeXmlBinding);
            }

            return true;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:26,代码来源:MimeXmlReflector.cs


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