Пример #1
0
		static Element RegisterType (Type type, string name, string namspace, bool reverseMap)
		{
			Element element = new Element (name, namspace);
			xmlNodeToTypeTable.Add (GetKey (name, namspace), type.AssemblyQualifiedName);
			if (reverseMap)
				typeToXmlNodeTable.Add (type.AssemblyQualifiedName, element);
			return element;
		}
Пример #2
0
		public Element GetXmlElement (string typeFullName, string assemblyName)
		{
			Element element;
			string typeNamespace = string.Empty;
			string typeName = typeFullName;
			if(_assemblyFormat == FormatterAssemblyStyle.Simple)
			{
				string[] items = assemblyName.Split(',');
				assemblyName = items[0];
			}
			string assemblyQualifiedName = typeFullName + ", " + assemblyName;
			element = (Element) typeToXmlNodeTable[assemblyQualifiedName];
			if(element == null)
			{
				int typeNameIndex = typeFullName.LastIndexOf('.');
				if(typeNameIndex != -1) 
				{
					typeNamespace = typeFullName.Substring(0, typeNameIndex);
					typeName = typeFullName.Substring(typeNamespace.Length + 1);
				}
				string namespaceURI = 
					SoapServices.CodeXmlNamespaceForClrTypeNamespace(
					typeNamespace, 
					(!assemblyName.StartsWith("mscorlib"))?assemblyName:String.Empty);
				string prefix = (string) namespaceToPrefixTable[namespaceURI];
				if(prefix == null || prefix == string.Empty)
				{
					prefix = "a" + (_prefixNumber++).ToString();
					namespaceToPrefixTable[namespaceURI] = prefix;

				}

				int i = typeName.IndexOf ("[");
				if (i != -1)
					typeName = XmlConvert.EncodeName (typeName.Substring (0, i)) + typeName.Substring (i);
				else
				{
					int j = typeName.IndexOf ("&");
					if (j != -1)
						typeName = XmlConvert.EncodeName (typeName.Substring (0, j)) + typeName.Substring (j);
					else
						typeName = XmlConvert.EncodeName (typeName);
				}

				element = new Element(
					prefix, 
					typeName, 
					namespaceURI);
			}
			return element;
		}
Пример #3
0
		public Element GetXmlElement (Type type)
		{
			if(type == typeof(string)) return elementString;
			Element element = (Element) typeToXmlNodeTable[type.AssemblyQualifiedName];
			if(element == null)
			{
				element = GetXmlElement (type.FullName, type.Assembly.FullName);
//					if(_assemblyFormat == FormatterAssemblyStyle.Full)
//						element = this[type.FullName, type.Assembly.FullName];
//					else
//						element = this[type.FullName, type.Assembly.GetName().Name];

			}
			else if (_xmlWriter != null)
			{
				element = new Element((element.Prefix == null)?_xmlWriter.LookupPrefix(element.NamespaceURI):element.Prefix, element.LocalName, element.NamespaceURI);
			}
			if(element == null)
				throw new SerializationException("Oooops");
			return element;
		}
Пример #4
0
		// Constructor used by SoapWriter
		public SoapTypeMapper(
			XmlTextWriter xmlWriter, 
			FormatterAssemblyStyle assemblyFormat,
			FormatterTypeStyle typeFormat) 
		{
			_xmlWriter = xmlWriter;
			_assemblyFormat = assemblyFormat;
			_prefixNumber = 1;
			//Type elementType = typeof(string);
			if(typeFormat == FormatterTypeStyle.XsdString)
			{
				elementString = new Element("xsd", "string", XmlSchema.Namespace);
			}
			else
			{
				elementString = new Element(SoapEncodingPrefix, "string", SoapEncodingNamespace);
			}
//			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
		}
Пример #5
0
		public string GetNamespacePrefix (Element xmlType)
		{
			string prefix = _xmlWriter.LookupPrefix (xmlType.NamespaceURI);
			if(prefix == null || prefix == string.Empty) 
			{
				_xmlWriter.WriteAttributeString(
					"xmlns",
					xmlType.Prefix,
					"http://www.w3.org/2000/xmlns/",
					xmlType.NamespaceURI);
				return xmlType.Prefix;
			}
			return prefix;
		}
		private static void InitMappingTables() 
		{
			Element element;
			Type elementType;
			element = new Element("Array", SoapEncodingNamespace);
			elementType = typeof(System.Array);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("string", XmlSchema.Namespace);
			elementType = typeof(string);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
//			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("string", SoapEncodingNamespace);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);

			element = new Element("boolean", XmlSchema.Namespace);
			elementType = typeof(bool);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("byte", XmlSchema.Namespace);
			elementType = typeof(sbyte);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("unsignedByte", XmlSchema.Namespace);
			elementType = typeof(byte);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("long", XmlSchema.Namespace);
			elementType = typeof(long);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("unsignedLong", XmlSchema.Namespace);
			elementType = typeof(ulong);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("int", XmlSchema.Namespace);
			elementType = typeof(int);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("unsignedInt", XmlSchema.Namespace);
			elementType = typeof(uint);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("float", XmlSchema.Namespace);
			elementType = typeof(float);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("double", XmlSchema.Namespace);
			elementType = typeof(double);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("decimal", XmlSchema.Namespace);
			elementType = typeof(decimal);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("short", XmlSchema.Namespace);
			elementType = typeof(short);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("unsignedShort", XmlSchema.Namespace);
			elementType = typeof(ushort);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("anyType", XmlSchema.Namespace);
			elementType = typeof(object);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("dateTime", XmlSchema.Namespace);
			elementType = typeof(DateTime);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("duration", XmlSchema.Namespace);
			elementType = typeof(TimeSpan);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("Fault", SoapEnvelopeNamespace);
			elementType = typeof(System.Runtime.Serialization.Formatters.SoapFault);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);

			element = new Element("base64", SoapEncodingNamespace);
			elementType = typeof(byte[]);
			xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
			typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
		}
		public Type this[Element element]
		{
			get 
			{
				Type type = null;

				string localName = XmlConvert.DecodeName(element.LocalName);
				string namespaceURI = XmlConvert.DecodeName(element.NamespaceURI);
				string typeNamespace, assemblyName;
				SoapServices.DecodeXmlNamespaceForClrTypeNamespace(
					element.NamespaceURI, 
					out typeNamespace, 
					out assemblyName);
				string typeName = typeNamespace + Type.Delimiter + localName;

				if(assemblyName != null && assemblyName != string.Empty && _binder != null) 
				{
					type = _binder.BindToType(assemblyName, typeName);
				}
				if(type == null) 
				{
					string assemblyQualifiedName = (string)xmlNodeToTypeTable[element];
					if(assemblyQualifiedName != null)
						type = Type.GetType(assemblyQualifiedName);
					else
					{ 

						type = Type.GetType(element.LocalName);
						if(type == null) 
						{ 

							type = Type.GetType(typeName);
							if(type == null) 
							{

								if(assemblyName == null || assemblyName == String.Empty)
									throw new SerializationException(
										String.Format("Parse Error, no assembly associated with XML key {0} {1}", 
										localName, 
										namespaceURI));
								type = FormatterServices.GetTypeFromAssembly(
									Assembly.Load(assemblyName), 
									typeName);
							}
						}
					}
					if(type == null)
						throw new SerializationException();
				}
				return type;
			}
		}
Пример #8
0
		private object Deserialize()
		{
			object objReturn = null;
			Element element = new Element(
				xmlReader.Prefix,
				xmlReader.LocalName,
				xmlReader.NamespaceURI);


			Type type = mapper[element];

			// Get the Id
			long id = GetId();
			id = (id == 0)?1:id;

			if(type == typeof(Array))
			{
				objReturn = DeserializeArray(id);
			}
			else
			{
				objReturn = DeserializeObject(type, id, 0, null, null);

			}

			return objReturn;