當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlTypeMapping.GetRealTypeMap方法代碼示例

本文整理匯總了C#中System.Xml.Serialization.XmlTypeMapping.GetRealTypeMap方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlTypeMapping.GetRealTypeMap方法的具體用法?C# XmlTypeMapping.GetRealTypeMap怎麽用?C# XmlTypeMapping.GetRealTypeMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Serialization.XmlTypeMapping的用法示例。


在下文中一共展示了XmlTypeMapping.GetRealTypeMap方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteObject

		protected virtual void WriteObject (XmlTypeMapping typeMap, object ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
		{
			if (ob == null)
			{
				if (isNullable) 
				{
					if (_format == SerializationFormat.Literal) WriteNullTagLiteral(element, namesp);
					else WriteNullTagEncoded (element, namesp);
				}
				return;
			}

			if (ob is XmlNode)
			{
				if (_format == SerializationFormat.Literal) WriteElementLiteral((XmlNode)ob, "", "", true, false);
				else WriteElementEncoded((XmlNode)ob, "", "", true, false);
				return;
			}

			if (typeMap.TypeData.SchemaType == SchemaTypes.XmlSerializable)
			{
				WriteSerializable ((IXmlSerializable)ob, element, namesp, isNullable);
				return;
			}

			XmlTypeMapping map = typeMap.GetRealTypeMap (ob.GetType());

			if (map == null) 
			{
				// bug #81539
				if (ob.GetType ().IsArray && typeof (XmlNode).IsAssignableFrom (ob.GetType ().GetElementType ())) {
					Writer.WriteStartElement (element, namesp);
					foreach (XmlNode node in (IEnumerable) ob)
						node.WriteTo (Writer);
					Writer.WriteEndElement ();
				}
				else
					WriteTypedPrimitive (element, namesp, ob, true);
				return;
			}

			if (writeWrappingElem)
			{
				if (map != typeMap || _format == SerializationFormat.Encoded) needType = true;
				WriteStartElement (element, namesp, ob);
			}

			if (needType) 
				WriteXsiType(map.XmlType, map.XmlTypeNamespace);

			switch (map.TypeData.SchemaType)
			{
				case SchemaTypes.Class: WriteObjectElement (map, ob, element, namesp); break;
				case SchemaTypes.Array: WriteListElement (map, ob, element, namesp); break;
				case SchemaTypes.Primitive: WritePrimitiveElement (map, ob, element, namesp); break;
				case SchemaTypes.Enum: WriteEnumElement (map, ob, element, namesp); break;
			}

			if (writeWrappingElem)
				WriteEndElement (ob);
		}
開發者ID:wamiq,項目名稱:debian-mono,代碼行數:61,代碼來源:XmlSerializationWriterInterpreter.cs


注:本文中的System.Xml.Serialization.XmlTypeMapping.GetRealTypeMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。