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


C# Serialization.XmlTypeMapElementInfo类代码示例

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


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

示例1: GenerateTextElementAttribute

		protected virtual void GenerateTextElementAttribute (CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, TypeData defaultType)
		{
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:3,代码来源:MapCodeGenerator.cs

示例2: ImportListMapping

		XmlTypeMapping ImportListMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace, XmlAttributes atts, int nestingLevel)
		{
			Type type = typeData.Type;
			ListMap obmap = new ListMap ();

			if (!allowPrivateTypes)
				ReflectionHelper.CheckSerializableType (type, true);
			
			if (atts == null) atts = new XmlAttributes();
			Type itemType = typeData.ListItemType;

			// warning: byte[][] should not be considered multiarray
			bool isMultiArray = (type.IsArray && (TypeTranslator.GetTypeData(itemType).SchemaType == SchemaTypes.Array) && itemType.IsArray);

			XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();

			foreach (XmlArrayItemAttribute att in atts.XmlArrayItems)
			{
				if (att.Namespace != null && att.Form == XmlSchemaForm.Unqualified)
					throw new InvalidOperationException ("XmlArrayItemAttribute.Form must not be Unqualified when it has an explicit Namespace value.");
				if (att.NestingLevel != nestingLevel) continue;
				Type elemType = (att.Type != null) ? att.Type : itemType;
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (null, TypeTranslator.GetTypeData(elemType, att.DataType));
				elem.Namespace = att.Namespace != null ? att.Namespace : defaultNamespace;
				if (elem.Namespace == null) elem.Namespace = "";
				elem.Form = att.Form;
				if (att.Form == XmlSchemaForm.Unqualified)
					elem.Namespace = string.Empty;
				elem.IsNullable = att.IsNullable && CanBeNull (elem.TypeData);
				elem.NestingLevel = att.NestingLevel;

				if (isMultiArray) {
					elem.MappedType = ImportListMapping (elemType, null, elem.Namespace, atts, nestingLevel + 1);
				} else if (elem.TypeData.IsComplexType) {
					elem.MappedType = ImportTypeMapping (elemType, null, elem.Namespace);
				}

				if (att.ElementName.Length != 0) {
					elem.ElementName = XmlConvert.EncodeLocalName (att.ElementName);
				} else if (elem.MappedType != null) {
					elem.ElementName = elem.MappedType.ElementName;
				} else {
					elem.ElementName = TypeTranslator.GetTypeData (elemType).XmlType;
				}

				list.Add (elem);
			}

			if (list.Count == 0)
			{
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (null, TypeTranslator.GetTypeData (itemType));
				if (isMultiArray)
					elem.MappedType = ImportListMapping (itemType, null, defaultNamespace, atts, nestingLevel + 1);
				else if (elem.TypeData.IsComplexType)
					elem.MappedType = ImportTypeMapping (itemType, null, defaultNamespace);

				if (elem.MappedType != null) {
					elem.ElementName = elem.MappedType.XmlType;
				} else {
					elem.ElementName = TypeTranslator.GetTypeData (itemType).XmlType;
				}

				elem.Namespace = (defaultNamespace != null) ? defaultNamespace : "";
				elem.IsNullable = CanBeNull (elem.TypeData);
				list.Add (elem);
			}

			obmap.ItemInfo = list;

			// If there can be different element names (types) in the array, then its name cannot
			// be "ArrayOfXXX" it must be something like ArrayOfChoiceNNN

			string baseName;
			if (list.Count > 1) {
				baseName = "ArrayOfChoice" + (arrayChoiceCount++);
			} else {
				XmlTypeMapElementInfo elem = ((XmlTypeMapElementInfo) list[0]);
				if (elem.MappedType != null) {
					baseName = TypeTranslator.GetArrayName (elem.MappedType.XmlType);
				} else {
					baseName = TypeTranslator.GetArrayName (elem.ElementName);
				}
			}

			// Avoid name colisions

			int nameCount = 1;
			string name = baseName;

			do {
				XmlTypeMapping foundMap = helper.GetRegisteredSchemaType (name, defaultNamespace);
				if (foundMap == null) nameCount = -1;
				else if (obmap.Equals (foundMap.ObjectMap) && typeData.Type == foundMap.TypeData.Type) return foundMap;
				else name = baseName + (nameCount++);
			}
			while (nameCount != -1);

			XmlTypeMapping map = CreateTypeMapping (typeData, root, name, defaultNamespace);
			map.ObjectMap = obmap;
			
//.........这里部分代码省略.........
开发者ID:anand-bhola,项目名称:mono,代码行数:101,代码来源:XmlReflectionImporter.cs

示例3: ImportElementInfo

		XmlTypeMapElementInfoList ImportElementInfo (Type cls, string defaultName, string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
		{
			EnumMap choiceEnumMap = null;
			Type choiceEnumType = null;
			
			XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
			ImportTextElementInfo (list, defaultType, member, atts, defaultNamespace);
			
			if (atts.XmlChoiceIdentifier != null) {
				if (cls == null)
					throw new InvalidOperationException ("XmlChoiceIdentifierAttribute not supported in this context.");
					
				member.ChoiceMember = atts.XmlChoiceIdentifier.MemberName;
				MemberInfo[] mems = cls.GetMember (member.ChoiceMember, BindingFlags.Instance|BindingFlags.Public);
				
				if (mems.Length == 0)
					throw new InvalidOperationException ("Choice member '" + member.ChoiceMember + "' not found in class '" + cls);
					
				if (mems[0] is PropertyInfo) {
					PropertyInfo pi = (PropertyInfo)mems[0];
					if (!pi.CanWrite || !pi.CanRead)
						throw new InvalidOperationException ("Choice property '" + member.ChoiceMember + "' must be read/write.");
					choiceEnumType = pi.PropertyType;
				}
				else choiceEnumType = ((FieldInfo)mems[0]).FieldType;
				
				member.ChoiceTypeData = TypeTranslator.GetTypeData (choiceEnumType);
				
				if (choiceEnumType.IsArray)
					choiceEnumType = choiceEnumType.GetElementType ();
				
				choiceEnumMap = ImportTypeMapping (choiceEnumType).ObjectMap as EnumMap;
				if (choiceEnumMap == null)
					throw new InvalidOperationException ("The member '" + mems[0].Name + "' is not a valid target for XmlChoiceIdentifierAttribute.");
			}
			
			if (atts.XmlElements.Count == 0 && list.Count == 0)
			{
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType));
				elem.ElementName = defaultName;
				elem.Namespace = defaultNamespace;
				if (elem.TypeData.IsComplexType)
					elem.MappedType = ImportTypeMapping (defaultType, null, defaultNamespace);
				list.Add (elem);
			}

			bool multiType = (atts.XmlElements.Count > 1);
			foreach (XmlElementAttribute att in atts.XmlElements)
			{
				Type elemType = (att.Type != null) ? att.Type : defaultType;
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(elemType, att.DataType));
				elem.Form = att.Form;
				if (elem.Form != XmlSchemaForm.Unqualified)
					elem.Namespace = (att.Namespace != null) ? att.Namespace : defaultNamespace;
				elem.IsNullable = att.IsNullable;

				if (elem.IsNullable && !elem.TypeData.IsNullable)
					throw new InvalidOperationException ("IsNullable may not be 'true' for value type " + elem.TypeData.FullTypeName + " in member '" + defaultName + "'");
					
				if (elem.TypeData.IsComplexType)
				{
					if (att.DataType.Length != 0) throw new InvalidOperationException (
						string.Format(CultureInfo.InvariantCulture, "'{0}' is "
							+ "an invalid value for '{1}.{2}' of type '{3}'. "
							+ "The property may only be specified for primitive types.",
							att.DataType, cls.FullName, defaultName, 
							elem.TypeData.FullTypeName));
					elem.MappedType = ImportTypeMapping (elemType, null, elem.Namespace);
				}

				if (att.ElementName.Length != 0)  {
					elem.ElementName = XmlConvert.EncodeLocalName(att.ElementName);
				} else if (multiType) {
					if (elem.MappedType != null) {
						elem.ElementName = elem.MappedType.ElementName;
					} else {
						elem.ElementName = TypeTranslator.GetTypeData (elemType).XmlType;
					}
				} else {
					elem.ElementName = defaultName;
				}

				if (choiceEnumMap != null) {
					string cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName, elem.ElementName);
					if (cname == null)
						throw new InvalidOperationException (string.Format (
							CultureInfo.InvariantCulture, "Type {0} is missing"
							+ " enumeration value '{1}' for element '{1} from"
							+ " namespace '{2}'.", choiceEnumType, elem.ElementName,
							elem.Namespace));
					elem.ChoiceValue = Enum.Parse (choiceEnumType, cname, false);
				}
					
				list.Add (elem);
			}
			return list;
		}
开发者ID:anand-bhola,项目名称:mono,代码行数:97,代码来源:XmlReflectionImporter.cs

示例4: CreateTextElementInfo

		XmlTypeMapElementInfo CreateTextElementInfo (string ns, XmlTypeMapMember member, TypeData typeData)
		{
			XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
			einfo.IsTextElement = true;
			einfo.WrappedElement = false;
			if (typeData.IsComplexType)
				einfo.MappedType = GetTypeMapping (typeData);
			return einfo;
		}
开发者ID:nestalk,项目名称:mono,代码行数:9,代码来源:XmlSchemaImporter.cs

示例5: ImportAnyElementInfo

		XmlTypeMapElementInfoList ImportAnyElementInfo (string defaultNamespace, XmlReflectionMember rmember, XmlTypeMapMemberElement member, XmlAttributes atts)
		{
			XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();

			ImportTextElementInfo (list, rmember.MemberType, member, atts, defaultNamespace);

#if !MOONLIGHT // no practical anyElement support
			foreach (XmlAnyElementAttribute att in atts.XmlAnyElements)
			{
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(typeof(XmlElement)));
				if (att.Name.Length != 0) 
				{
					elem.ElementName = XmlConvert.EncodeLocalName(att.Name);
					elem.Namespace = (att.Namespace != null) ? att.Namespace : "";
				}
				else 
				{
					elem.IsUnnamedAnyElement = true;
					elem.Namespace = defaultNamespace;
					if (att.Namespace != null) 
						throw new InvalidOperationException ("The element " + rmember.MemberName + " has been attributed with an XmlAnyElementAttribute and a namespace '" + att.Namespace + "', but no name. When a namespace is supplied, a name is also required. Supply a name or remove the namespace.");
				}
				list.Add (elem);
			}
#endif
			return list;
		}
开发者ID:anand-bhola,项目名称:mono,代码行数:27,代码来源:XmlReflectionImporter.cs

示例6: GenerateReadPrimitiveValue

		string GenerateReadPrimitiveValue (XmlTypeMapElementInfo elem)
		{
			if (elem.TypeData.Type == typeof (XmlQualifiedName)) {
				if (elem.IsNullable) return "ReadNullableQualifiedName ()";
				else return "ReadElementQualifiedName ()";
			}
			else if (elem.IsNullable) {
				string str = GetStrTempVar ();
				WriteLine ("string " + str + " = ReadNullableString ();");
				return GenerateGetValueFromXmlString (str, elem.TypeData, elem.MappedType, true);
			}
			else {
				string str = GetStrTempVar ();
				WriteLine ("string " + str + " = Reader.ReadElementString ();");
				return GenerateGetValueFromXmlString (str, elem.TypeData, elem.MappedType, false);
			}
		}
开发者ID:thenextman,项目名称:mono,代码行数:17,代码来源:SerializationCodeGenerator.cs

示例7: ImportChoices

		bool ImportChoices (XmlQualifiedName typeQName, XmlTypeMapMember member, XmlTypeMapElementInfoList choices, XmlSchemaObjectCollection items)
		{
			bool multiValue = false;
			foreach (XmlSchemaObject titem in items)
			{
				XmlSchemaObject item = titem;
				if (item is XmlSchemaGroupRef)
					item = GetRefGroupParticle ((XmlSchemaGroupRef)item);

				if (item is XmlSchemaElement)
				{
					string ns;
					XmlSchemaElement elem = (XmlSchemaElement) item;
					XmlTypeMapping emap;
					TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);
					XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
					choices.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap, -1));
					if (elem.MaxOccurs > 1) multiValue = true;
				}
				else if (item is XmlSchemaAny)
				{
					XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(typeof(XmlElement)));
					einfo.IsUnnamedAnyElement = true;
					choices.Add (einfo);
				}
				else if (item is XmlSchemaChoice) {
					multiValue = ImportChoices (typeQName, member, choices, ((XmlSchemaChoice)item).Items) || multiValue;
				}
				else if (item is XmlSchemaSequence) {
					multiValue = ImportChoices (typeQName, member, choices, ((XmlSchemaSequence)item).Items) || multiValue;
				}
			}
			return multiValue;
		}
开发者ID:nestalk,项目名称:mono,代码行数:34,代码来源:XmlSchemaImporter.cs

示例8: GetSchemaElement

		XmlSchemaParticle GetSchemaElement (XmlSchema currentSchema, XmlTypeMapElementInfo einfo, bool isTypeMember, XmlSchemaObjectContainer container)
		{
			return GetSchemaElement (currentSchema, einfo, System.DBNull.Value, isTypeMember, container);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:4,代码来源:XmlSchemaExporter.cs

示例9: ReadPrimitiveValue

		object ReadPrimitiveValue (XmlTypeMapElementInfo elem)
		{
			if (elem.TypeData.Type == typeof (XmlQualifiedName)) {
				if (elem.IsNullable) return ReadNullableQualifiedName ();
				else return ReadElementQualifiedName ();
			}
			else if (elem.IsNullable)
				return GetValueFromXmlString (ReadNullableString (), elem.TypeData, elem.MappedType);
			else
				return GetValueFromXmlString (Reader.ReadElementString (), elem.TypeData, elem.MappedType);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:XmlSerializationReaderInterpreter.cs

示例10: ExportTypeMapping

		public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
		{
			if (!xmlTypeMapping.IncludeInSchema) return;
			if (IsElementExported (xmlTypeMapping)) return;
			
			if (encodedFormat)
			{
				ExportClassSchema (xmlTypeMapping);
				XmlSchema schema = GetSchema (xmlTypeMapping.XmlTypeNamespace);
				ImportNamespace (schema, XmlSerializer.EncodingNamespace);
			}
			else
			{
				XmlSchema schema = GetSchema (xmlTypeMapping.Namespace);
				XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (null, xmlTypeMapping.TypeData);
				einfo.Namespace = xmlTypeMapping.Namespace;
				einfo.ElementName = xmlTypeMapping.ElementName;
				if (xmlTypeMapping.TypeData.IsComplexType)
					einfo.MappedType = xmlTypeMapping;
				einfo.IsNullable = xmlTypeMapping.IsNullable;
				GetSchemaElement (schema, einfo, false, new XmlSchemaObjectContainer (schema));
				SetElementExported (xmlTypeMapping);
			}
			
			CompileSchemas ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:26,代码来源:XmlSchemaExporter.cs

示例11: ReadObjectElement

		object ReadObjectElement (XmlTypeMapElementInfo elem)
		{
			switch (elem.TypeData.SchemaType)
			{
				case SchemaTypes.XmlNode:
					return ReadXmlNode (elem.TypeData, true);

				case SchemaTypes.Primitive:
				case SchemaTypes.Enum:
					return ReadPrimitiveValue (elem);

				case SchemaTypes.Array:
					return ReadListElement (elem.MappedType, elem.IsNullable, null, true);

				case SchemaTypes.Class:
					return ReadObject (elem.MappedType, elem.IsNullable, true);

				case SchemaTypes.XmlSerializable:
					object ob = Activator.CreateInstance (elem.TypeData.Type, true);
					return ReadSerializable ((IXmlSerializable)ob);

				default:
					throw new NotSupportedException ("Invalid value type");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:25,代码来源:XmlSerializationReaderInterpreter.cs

示例12: CreateMapMember

		private XmlTypeMapMember CreateMapMember (XmlReflectionMember rmember, string defaultNamespace)
		{
			XmlTypeMapMember mapMember;
			SoapAttributes atts = rmember.SoapAttributes;
			TypeData typeData = TypeTranslator.GetTypeData (rmember.MemberType);

			if (atts.SoapAttribute != null)
			{
				// An attribute

				if (atts.SoapElement != null)
					throw new Exception ("SoapAttributeAttribute and SoapElementAttribute cannot be applied to the same member");

				XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute ();
				if (atts.SoapAttribute.AttributeName == null) 
					mapAttribute.AttributeName = rmember.MemberName;
				else 
					mapAttribute.AttributeName = atts.SoapAttribute.AttributeName;

				mapAttribute.Namespace = (atts.SoapAttribute.Namespace != null) ? atts.SoapAttribute.Namespace : "";
				if (typeData.IsComplexType)
					mapAttribute.MappedType = ImportTypeMapping (typeData.Type, defaultNamespace);

				typeData = TypeTranslator.GetTypeData (rmember.MemberType, atts.SoapAttribute.DataType);
				mapMember = mapAttribute;
			}
			else
			{
				if (typeData.SchemaType == SchemaTypes.Array) mapMember = new XmlTypeMapMemberList ();
				else mapMember = new XmlTypeMapMemberElement ();

				if (atts.SoapElement != null && atts.SoapElement.DataType != null)
					typeData = TypeTranslator.GetTypeData (rmember.MemberType, atts.SoapElement.DataType);

				// Creates an ElementInfo that identifies the element
				XmlTypeMapElementInfoList infoList = new XmlTypeMapElementInfoList();
				XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (mapMember, typeData);

				elem.ElementName = (atts.SoapElement != null && atts.SoapElement.ElementName != null) ? atts.SoapElement.ElementName : rmember.MemberName;
				elem.Namespace = string.Empty;
				elem.IsNullable = (atts.SoapElement != null) ? atts.SoapElement.IsNullable : false;
				if (typeData.IsComplexType)
					elem.MappedType = ImportTypeMapping (typeData.Type, defaultNamespace);
				
				infoList.Add (elem);
				((XmlTypeMapMemberElement)mapMember).ElementInfo = infoList;
			}

			mapMember.TypeData = typeData;
			mapMember.Name = rmember.MemberName;
			mapMember.IsReturnValue = rmember.IsReturnValue;
			return mapMember;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:53,代码来源:SoapReflectionImporter.cs

示例13: GenerateUnnamedAnyElementAttribute

		protected virtual void GenerateUnnamedAnyElementAttribute (CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, string defaultNamespace)
		{
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:3,代码来源:MapCodeGenerator.cs

示例14: CreateElementInfo

		XmlTypeMapElementInfo CreateElementInfo (string ns, XmlTypeMapMember member, string name, TypeData typeData, bool isNillable, XmlSchemaForm form, XmlTypeMapping emap)
		{
			XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
			einfo.ElementName = name;
			einfo.Namespace = ns;
			einfo.IsNullable = isNillable;
			einfo.Form = form;
			if (typeData.IsComplexType)
				einfo.MappedType = emap;
			return einfo;
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:11,代码来源:XmlSchemaImporter.cs

示例15: GenerateElementInfoMember

		protected override void GenerateElementInfoMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName)
		{
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlElementAttribute");
			if (forceUseMemberName || einfo.ElementName != member.Name) att.Arguments.Add (GetArg (einfo.ElementName));
			if (einfo.TypeData.FullTypeName != defaultType.FullTypeName) att.Arguments.Add (GetTypeArg ("Type", einfo.TypeData.FullTypeName));
			if (einfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
			if (einfo.Form == XmlSchemaForm.Unqualified) att.Arguments.Add (GetEnumArg ("Form", "System.Xml.Schema.XmlSchemaForm", einfo.Form.ToString()));
			if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true));
			if (!TypeTranslator.IsDefaultPrimitiveTpeData(einfo.TypeData)) att.Arguments.Add (GetArg ("DataType",einfo.TypeData.XmlType));
			if (addAlwaysAttr || att.Arguments.Count > 0) attributes.Add (att);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:11,代码来源:XmlCodeExporter.cs


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