SoapCommonClasses.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / ManagedLibraries / SoapSerializer / SoapCommonClasses.cs / 1 / SoapCommonClasses.cs

                            // ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
//============================================================
// 
// Class: SoapCommonClasses 
//
// Author: Peter de Jong ([....]) 
//
// Purpose: utility classes
//
// Date:  June 10, 1999 
//
//=========================================================== 
 
namespace System.Runtime.Serialization.Formatters.Soap
{ 
 	using System;
	using System.Collections;
	using System.Reflection;
	using System.Text; 
 	using System.Globalization;
	using System.Runtime.Serialization.Formatters; 
 	using System.Runtime.Remoting; 
 	using System.Runtime.Remoting.Metadata;
	using System.Runtime.Remoting.Messaging; 
 	using System.Runtime.InteropServices;
	using System.Runtime.Serialization;
	using System.Resources;
	using System.Diagnostics; 

 	// AttributeList class is used to transmit attributes from XMLObjectWriter to XMLWriter 
	internal sealed class AttributeList 
 	{
 		private SerStack nameA = new SerStack("AttributeName"); 
		private SerStack valueA = new SerStack("AttributeValue");

 		internal int Count
		{ 
			get {return nameA.Count();}
		} 
 
 		internal void Clear()
		{ 
 			nameA.Clear();
 			valueA.Clear();			
		}
 
 		internal void Put(String name, String value)
		{ 
			nameA.Push(name); 
			valueA.Push(value);
 		} 

		internal void Get(int index, out String name, out String value)
 		{
 			name = (String)nameA.Next(); 
			value = (String)valueA.Next();
 		} 
 
		[Conditional("SER_LOGGING")]							
		internal void Dump() 
		{
 			nameA.Dump();
			valueA.Dump();
 		} 
 	}
 
	// Implements a stack used for parsing 

 	internal sealed class SerStack 
	{
		//internal ArrayList stack = new ArrayList(10);
		internal Object[] objects = new Object[10];
 		internal String stackId; 
		internal int top = -1;
 		internal int next = 0; 
 
 		internal SerStack(String stackId) {
			this.stackId = stackId; 
 		}

		internal Object GetItem(int index)
		{ 
			return objects[index];
 		} 
 
		internal void Clear()
 		{ 
 			top = -1;
			next = 0;
 		}
 
		// Push the object onto the stack
		internal void Push(Object obj) { 
			InternalST.Soap(this, "Push ",stackId," ",((obj is ITrace)?((ITrace)obj).Trace():""));									 
 			if (top == (objects.Length -1)) {
				IncreaseCapacity(); 
 			}
 			objects[++top] = obj;		
		}
 
 		// Pop the object from the stack
		internal Object Pop() { 
			if (top < 0) 
				return null;
 
 			Object obj = objects[top];
			objects[top--] = null;
 			InternalST.Soap(this, "Pop ",stackId," ",((obj is ITrace)?((ITrace)obj).Trace():""));			
 			return obj; 
		}
 
 		internal Object Next() 
		{
			if (next > top) 
				throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_StackRange"),stackId));				
 			return objects[next++];
		}
 
 		internal void IncreaseCapacity() {
 			int size = objects.Length * 2; 
			Object[] newItems = new Object[size]; 
 			Array.Copy(objects, 0, newItems, 0, objects.Length);
			objects = newItems; 
		}

		// Gets the object on the top of the stack
 		internal Object Peek() { 
			if (top < 0)
 				return null;		 
 			InternalST.Soap(this, "Peek ",stackId," ",((objects[top] is ITrace)?((ITrace)objects[top]).Trace():""));			 
			return objects[top];
 		} 

		// Gets the second entry in the stack.
		internal Object PeekPeek() {
			if (top < 1) 
 				return null;
			InternalST.Soap(this, "PeekPeek ",stackId," ",((objects[top - 1] is ITrace)?((ITrace)objects[top - 1]).Trace():""));									 
 			return objects[top - 1];		 
 		}
 
		// The number of entries in the stack
 		internal int Count() {
			return top + 1;
		} 

		// The number of entries in the stack 
 		internal bool IsEmpty() { 
			if (top > 0)
 				return false; 
 			else
				return true;
 		}
 
		// Reverse the stack
		internal void Reverse() { 
			Array.Reverse(objects, 0, Count()); 
 		}
 
		[Conditional("SER_LOGGING")]								
 		internal void Dump()
 		{
			for (int i=0; i 0) 
 				return true;
 			else 
				return false; 
 		}
 
		internal bool IsXmlElement()
		{
			if ((m_attributeType & SoapAttributeType.XmlElement) > 0)
 				return true; 
			else
 				return false; 
 		} 

		internal bool IsXmlAttribute() 
 		{
			if ((m_attributeType & SoapAttributeType.XmlAttribute) > 0)
				return true;
			else 
 				return false;
		} 
 
 		internal bool IsXmlType()
 		{ 
			if ((m_attributeType & SoapAttributeType.XmlType) > 0)
 				return true;
			else
				return false; 
		}
 		 
		[Conditional("SER_LOGGING")] 
 		internal void Dump(String id)
 		{ 
			InternalST.Soap("Dump SoapAttributeInfo ", id);
 			if (IsXmlType())
				InternalST.Soap("   SchemaType");
			if (IsEmbedded()) 
				InternalST.Soap("   Embedded");
 			if (IsXmlElement()) 
				InternalST.Soap("   XmlElement"); 
 			if (IsXmlAttribute())
 				InternalST.Soap("   XmlAttribute");			 
			Util.NVTrace("_nameSpace", m_nameSpace);
 			Util.NVTrace("_elementName", m_elementName);
			Util.NVTrace("_type", m_typeName);			
		} 
	}
 
 	internal sealed class NameInfo 
	{
 		internal InternalNameSpaceE NInameSpaceEnum = InternalNameSpaceE.None; 
 		internal String NIname; // Name from SerObjectInfo.GetType
		//internal String elementName; // Name from SerObjectInfo.GetElementName, will be the same as GetType except for interopTypes
 		//internal String interopType;
		internal long NIobjectId; 
		internal long NIassemId;
		internal InternalPrimitiveTypeE NIprimitiveTypeEnum = InternalPrimitiveTypeE.Invalid; 
 		internal Type NItype; 
		internal bool NIisSealed;
 		internal bool NIisMustUnderstand; 
 		internal String NInamespace;
		internal String NIheaderPrefix;
 		internal String NIitemName;
		internal bool NIisArray; 
		internal bool NIisArrayItem;
		internal bool NIisTopLevelObject; 
 		internal bool NIisNestedObject; 
		internal bool NItransmitTypeOnObject;
 		internal bool NItransmitTypeOnMember; 
 		internal bool NIisParentTypeOnObject;
		internal bool NIisHeader;
          internal bool NIisRemoteRecord;
 		internal SoapAttributeInfo NIattributeInfo; 

		internal void Init() 
		{ 
			NInameSpaceEnum = InternalNameSpaceE.None;
 			NIname = null; 
			NIobjectId = 0;
 			NIassemId = 0;
 			NIprimitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
			NItype = null; 
 			NIisSealed = false;
			NItransmitTypeOnObject = false; 
			NItransmitTypeOnMember = false; 
			NIisParentTypeOnObject = false;
 			NIisMustUnderstand = false; 
			NInamespace = null;
 			NIheaderPrefix = null;
 			NIitemName = null;
			NIisArray = false; 
 			NIisArrayItem = false;
			NIisTopLevelObject = false; 
			NIisNestedObject = false; 
			NIisHeader = false;
            NIisRemoteRecord = false; 
 			NIattributeInfo = null;
		}

 		[Conditional("SER_LOGGING")] 
 		internal void Dump(String value)
		{ 
 			Util.NVTrace("nameSpaceEnum", ((Enum)NInameSpaceEnum).ToString()); 
			Util.NVTrace("name", NIname);
			Util.NVTrace("objectId", NIobjectId); 
			Util.NVTrace("assemId", NIassemId);
 			Util.NVTrace("primitiveTypeEnum", ((Enum)NIprimitiveTypeEnum).ToString());
			Util.NVTrace("type", NItype);
 			Util.NVTrace("isSealed", NIisSealed);			 
 			Util.NVTrace("transmitTypeOnObject", NItransmitTypeOnObject);
			Util.NVTrace("transmitTypeOnMember", NItransmitTypeOnMember); 
 			Util.NVTrace("isParentTypeOnObject", NIisParentTypeOnObject);				 
			Util.NVTrace("isMustUnderstand", NIisMustUnderstand);
			Util.NVTrace("namespace", NInamespace); 
			Util.NVTrace("headerPrefix", NIheaderPrefix);
 			Util.NVTrace("itemName", NIitemName);				
			Util.NVTrace("isArray", NIisArray);
 			Util.NVTrace("isArrayItem", NIisArrayItem); 
 			Util.NVTrace("isTopLevelObject", NIisTopLevelObject);
			Util.NVTrace("isNestedObject", NIisNestedObject); 
 			Util.NVTrace("isHeader", NIisHeader); 
			Util.NVTrace("isRemoteRecord", NIisRemoteRecord);
			if (NIattributeInfo != null) 
				NIattributeInfo.Dump(NIname);
 		}

	} 

 	internal sealed class PrimitiveArray 
 	{ 
		InternalPrimitiveTypeE code;
 		Boolean[] booleanA = null; 
		Char[] charA = null;
		Double[] doubleA = null;
		Int16[] int16A = null;
 		Int32[] int32A = null; 
		Int64[] int64A = null;
 		SByte[] sbyteA = null; 
 		Single[] singleA = null; 
		UInt16[] uint16A = null;
 		UInt32[] uint32A = null; 
		UInt64[] uint64A = null;


		internal PrimitiveArray(InternalPrimitiveTypeE code, Array array) 
		{
 			Init(code, array); 
		} 

 		internal void Init(InternalPrimitiveTypeE code, Array array) 
 		{
			this.code = code;
 			switch(code)
			{ 
				case InternalPrimitiveTypeE.Boolean:
					booleanA = (Boolean[])array; 
 					break; 
				case InternalPrimitiveTypeE.Char:
 					charA = (Char[])array; 
 					break;					
				case InternalPrimitiveTypeE.Double:
 					doubleA = (Double[])array;
					break;					 
				case InternalPrimitiveTypeE.Int16:
					int16A = (Int16[])array; 
 					break;					 
				case InternalPrimitiveTypeE.Int32:
 					int32A = (Int32[])array; 
 					break;					
				case InternalPrimitiveTypeE.Int64:
 					int64A = (Int64[])array;
					break;					 
				case InternalPrimitiveTypeE.SByte:
					sbyteA = (SByte[])array; 
 					break;					 
				case InternalPrimitiveTypeE.Single:
 					singleA = (Single[])array; 
 					break;					
				case InternalPrimitiveTypeE.UInt16:
 					uint16A = (UInt16[])array;
					break;					 
				case InternalPrimitiveTypeE.UInt32:
					uint32A = (UInt32[])array; 
 					break;					 
				case InternalPrimitiveTypeE.UInt64:
 					uint64A = (UInt64[])array; 
 					break;
			}
 		}
 
		internal String GetValue(int index)
		{ 
			String value = null; 
 			switch(code)
			{ 
 				case InternalPrimitiveTypeE.Boolean:
 					value =  (booleanA[index]).ToString();
					break;
 				case InternalPrimitiveTypeE.Char: 
					if (charA[index] == Char.MinValue)
						value = "_0x00_"; 
					else 
 						value =  Char.ToString(charA[index]);
					break;					 
                case InternalPrimitiveTypeE.Double:
                    if (Double.IsPositiveInfinity(doubleA[index]))
                        value = "INF";
                    else if (Double.IsNegativeInfinity(doubleA[index])) 
                        value = "-INF";
                    else 
                        value =  (doubleA[index]).ToString("R", CultureInfo.InvariantCulture); 
 					break;					
 				case InternalPrimitiveTypeE.Int16: 
					value =  (int16A[index]).ToString(CultureInfo.InvariantCulture);
 					break;					
				case InternalPrimitiveTypeE.Int32:
					value =  (int32A[index]).ToString(CultureInfo.InvariantCulture); 
					break;					
 				case InternalPrimitiveTypeE.Int64: 
					value =  (int64A[index]).ToString(CultureInfo.InvariantCulture); 
 					break;					
 				case InternalPrimitiveTypeE.SByte: 
					value =  (sbyteA[index]).ToString(CultureInfo.InvariantCulture);
 					break;					
                case InternalPrimitiveTypeE.Single:
                    if (Single.IsPositiveInfinity(singleA[index])) 
                        value = "INF";
                    else if (Single.IsNegativeInfinity(singleA[index])) 
                        value = "-INF"; 
                    else
                        value =  (singleA[index]).ToString("R", CultureInfo.InvariantCulture); 
					break;
				case InternalPrimitiveTypeE.UInt16:
					value =  (uint16A[index]).ToString(CultureInfo.InvariantCulture);
 					break; 
				case InternalPrimitiveTypeE.UInt32:
 					value =  (uint32A[index]).ToString(CultureInfo.InvariantCulture); 
 					break;					 
				case InternalPrimitiveTypeE.UInt64:
 					value =  (uint64A[index]).ToString(CultureInfo.InvariantCulture); 
					break;					
			}
			return value;
 		} 

		internal void SetValue(String value, int index) 
 		{ 
 			InternalST.Soap("PrimitiveArray value ", value," index ", index, " code ",((Enum)code).ToString());
			switch(code) 
 			{
				case InternalPrimitiveTypeE.Boolean:
					booleanA[index] = Boolean.Parse(value);
					break; 
 				case InternalPrimitiveTypeE.Char:
					if ((value[0] == '_') && (value.Equals("_0x00_"))) 
 						charA[index] = Char.MinValue; 
 					else
						charA[index] = Char.Parse(value); 
 					break;					
                case InternalPrimitiveTypeE.Double:
                    if (value == "INF")
                        doubleA[index] =  Double.PositiveInfinity; 
                    else if (value == "-INF")
                        doubleA[index] =  Double.NegativeInfinity; 
                    else 
                        doubleA[index] = Double.Parse(value, CultureInfo.InvariantCulture);
					break;					 
				case InternalPrimitiveTypeE.Int16:
					int16A[index] = Int16.Parse(value, CultureInfo.InvariantCulture);															
 					break;					
				case InternalPrimitiveTypeE.Int32: 
 					int32A[index] = Int32.Parse(value, CultureInfo.InvariantCulture);																				
 					break;					 
				case InternalPrimitiveTypeE.Int64: 
 					int64A[index] = Int64.Parse(value, CultureInfo.InvariantCulture);																									
					break;					 
				case InternalPrimitiveTypeE.SByte:
					sbyteA[index] = SByte.Parse(value, CultureInfo.InvariantCulture);
 					break;					
                case InternalPrimitiveTypeE.Single: 
                    if (value == "INF")
                        singleA[index] =  Single.PositiveInfinity; 
                    else if (value == "-INF") 
                        singleA[index] =  Single.NegativeInfinity;
                    else 
                        singleA[index] = Single.Parse(value, CultureInfo.InvariantCulture);
					break;
 				case InternalPrimitiveTypeE.UInt16:
 					uint16A[index] = UInt16.Parse(value, CultureInfo.InvariantCulture); 
					break;
 				case InternalPrimitiveTypeE.UInt32: 
					uint32A[index] = UInt32.Parse(value, CultureInfo.InvariantCulture);					 
					break;					
				case InternalPrimitiveTypeE.UInt64: 
 					uint64A[index] = UInt64.Parse(value, CultureInfo.InvariantCulture);					
					break;					
 			}
 		} 
	}
} 
 

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
//============================================================
// 
// Class: SoapCommonClasses 
//
// Author: Peter de Jong ([....]) 
//
// Purpose: utility classes
//
// Date:  June 10, 1999 
//
//=========================================================== 
 
namespace System.Runtime.Serialization.Formatters.Soap
{ 
 	using System;
	using System.Collections;
	using System.Reflection;
	using System.Text; 
 	using System.Globalization;
	using System.Runtime.Serialization.Formatters; 
 	using System.Runtime.Remoting; 
 	using System.Runtime.Remoting.Metadata;
	using System.Runtime.Remoting.Messaging; 
 	using System.Runtime.InteropServices;
	using System.Runtime.Serialization;
	using System.Resources;
	using System.Diagnostics; 

 	// AttributeList class is used to transmit attributes from XMLObjectWriter to XMLWriter 
	internal sealed class AttributeList 
 	{
 		private SerStack nameA = new SerStack("AttributeName"); 
		private SerStack valueA = new SerStack("AttributeValue");

 		internal int Count
		{ 
			get {return nameA.Count();}
		} 
 
 		internal void Clear()
		{ 
 			nameA.Clear();
 			valueA.Clear();			
		}
 
 		internal void Put(String name, String value)
		{ 
			nameA.Push(name); 
			valueA.Push(value);
 		} 

		internal void Get(int index, out String name, out String value)
 		{
 			name = (String)nameA.Next(); 
			value = (String)valueA.Next();
 		} 
 
		[Conditional("SER_LOGGING")]							
		internal void Dump() 
		{
 			nameA.Dump();
			valueA.Dump();
 		} 
 	}
 
	// Implements a stack used for parsing 

 	internal sealed class SerStack 
	{
		//internal ArrayList stack = new ArrayList(10);
		internal Object[] objects = new Object[10];
 		internal String stackId; 
		internal int top = -1;
 		internal int next = 0; 
 
 		internal SerStack(String stackId) {
			this.stackId = stackId; 
 		}

		internal Object GetItem(int index)
		{ 
			return objects[index];
 		} 
 
		internal void Clear()
 		{ 
 			top = -1;
			next = 0;
 		}
 
		// Push the object onto the stack
		internal void Push(Object obj) { 
			InternalST.Soap(this, "Push ",stackId," ",((obj is ITrace)?((ITrace)obj).Trace():""));									 
 			if (top == (objects.Length -1)) {
				IncreaseCapacity(); 
 			}
 			objects[++top] = obj;		
		}
 
 		// Pop the object from the stack
		internal Object Pop() { 
			if (top < 0) 
				return null;
 
 			Object obj = objects[top];
			objects[top--] = null;
 			InternalST.Soap(this, "Pop ",stackId," ",((obj is ITrace)?((ITrace)obj).Trace():""));			
 			return obj; 
		}
 
 		internal Object Next() 
		{
			if (next > top) 
				throw new SerializationException(String.Format(CultureInfo.CurrentCulture, SoapUtil.GetResourceString("Serialization_StackRange"),stackId));				
 			return objects[next++];
		}
 
 		internal void IncreaseCapacity() {
 			int size = objects.Length * 2; 
			Object[] newItems = new Object[size]; 
 			Array.Copy(objects, 0, newItems, 0, objects.Length);
			objects = newItems; 
		}

		// Gets the object on the top of the stack
 		internal Object Peek() { 
			if (top < 0)
 				return null;		 
 			InternalST.Soap(this, "Peek ",stackId," ",((objects[top] is ITrace)?((ITrace)objects[top]).Trace():""));			 
			return objects[top];
 		} 

		// Gets the second entry in the stack.
		internal Object PeekPeek() {
			if (top < 1) 
 				return null;
			InternalST.Soap(this, "PeekPeek ",stackId," ",((objects[top - 1] is ITrace)?((ITrace)objects[top - 1]).Trace():""));									 
 			return objects[top - 1];		 
 		}
 
		// The number of entries in the stack
 		internal int Count() {
			return top + 1;
		} 

		// The number of entries in the stack 
 		internal bool IsEmpty() { 
			if (top > 0)
 				return false; 
 			else
				return true;
 		}
 
		// Reverse the stack
		internal void Reverse() { 
			Array.Reverse(objects, 0, Count()); 
 		}
 
		[Conditional("SER_LOGGING")]								
 		internal void Dump()
 		{
			for (int i=0; i 0) 
 				return true;
 			else 
				return false; 
 		}
 
		internal bool IsXmlElement()
		{
			if ((m_attributeType & SoapAttributeType.XmlElement) > 0)
 				return true; 
			else
 				return false; 
 		} 

		internal bool IsXmlAttribute() 
 		{
			if ((m_attributeType & SoapAttributeType.XmlAttribute) > 0)
				return true;
			else 
 				return false;
		} 
 
 		internal bool IsXmlType()
 		{ 
			if ((m_attributeType & SoapAttributeType.XmlType) > 0)
 				return true;
			else
				return false; 
		}
 		 
		[Conditional("SER_LOGGING")] 
 		internal void Dump(String id)
 		{ 
			InternalST.Soap("Dump SoapAttributeInfo ", id);
 			if (IsXmlType())
				InternalST.Soap("   SchemaType");
			if (IsEmbedded()) 
				InternalST.Soap("   Embedded");
 			if (IsXmlElement()) 
				InternalST.Soap("   XmlElement"); 
 			if (IsXmlAttribute())
 				InternalST.Soap("   XmlAttribute");			 
			Util.NVTrace("_nameSpace", m_nameSpace);
 			Util.NVTrace("_elementName", m_elementName);
			Util.NVTrace("_type", m_typeName);			
		} 
	}
 
 	internal sealed class NameInfo 
	{
 		internal InternalNameSpaceE NInameSpaceEnum = InternalNameSpaceE.None; 
 		internal String NIname; // Name from SerObjectInfo.GetType
		//internal String elementName; // Name from SerObjectInfo.GetElementName, will be the same as GetType except for interopTypes
 		//internal String interopType;
		internal long NIobjectId; 
		internal long NIassemId;
		internal InternalPrimitiveTypeE NIprimitiveTypeEnum = InternalPrimitiveTypeE.Invalid; 
 		internal Type NItype; 
		internal bool NIisSealed;
 		internal bool NIisMustUnderstand; 
 		internal String NInamespace;
		internal String NIheaderPrefix;
 		internal String NIitemName;
		internal bool NIisArray; 
		internal bool NIisArrayItem;
		internal bool NIisTopLevelObject; 
 		internal bool NIisNestedObject; 
		internal bool NItransmitTypeOnObject;
 		internal bool NItransmitTypeOnMember; 
 		internal bool NIisParentTypeOnObject;
		internal bool NIisHeader;
          internal bool NIisRemoteRecord;
 		internal SoapAttributeInfo NIattributeInfo; 

		internal void Init() 
		{ 
			NInameSpaceEnum = InternalNameSpaceE.None;
 			NIname = null; 
			NIobjectId = 0;
 			NIassemId = 0;
 			NIprimitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
			NItype = null; 
 			NIisSealed = false;
			NItransmitTypeOnObject = false; 
			NItransmitTypeOnMember = false; 
			NIisParentTypeOnObject = false;
 			NIisMustUnderstand = false; 
			NInamespace = null;
 			NIheaderPrefix = null;
 			NIitemName = null;
			NIisArray = false; 
 			NIisArrayItem = false;
			NIisTopLevelObject = false; 
			NIisNestedObject = false; 
			NIisHeader = false;
            NIisRemoteRecord = false; 
 			NIattributeInfo = null;
		}

 		[Conditional("SER_LOGGING")] 
 		internal void Dump(String value)
		{ 
 			Util.NVTrace("nameSpaceEnum", ((Enum)NInameSpaceEnum).ToString()); 
			Util.NVTrace("name", NIname);
			Util.NVTrace("objectId", NIobjectId); 
			Util.NVTrace("assemId", NIassemId);
 			Util.NVTrace("primitiveTypeEnum", ((Enum)NIprimitiveTypeEnum).ToString());
			Util.NVTrace("type", NItype);
 			Util.NVTrace("isSealed", NIisSealed);			 
 			Util.NVTrace("transmitTypeOnObject", NItransmitTypeOnObject);
			Util.NVTrace("transmitTypeOnMember", NItransmitTypeOnMember); 
 			Util.NVTrace("isParentTypeOnObject", NIisParentTypeOnObject);				 
			Util.NVTrace("isMustUnderstand", NIisMustUnderstand);
			Util.NVTrace("namespace", NInamespace); 
			Util.NVTrace("headerPrefix", NIheaderPrefix);
 			Util.NVTrace("itemName", NIitemName);				
			Util.NVTrace("isArray", NIisArray);
 			Util.NVTrace("isArrayItem", NIisArrayItem); 
 			Util.NVTrace("isTopLevelObject", NIisTopLevelObject);
			Util.NVTrace("isNestedObject", NIisNestedObject); 
 			Util.NVTrace("isHeader", NIisHeader); 
			Util.NVTrace("isRemoteRecord", NIisRemoteRecord);
			if (NIattributeInfo != null) 
				NIattributeInfo.Dump(NIname);
 		}

	} 

 	internal sealed class PrimitiveArray 
 	{ 
		InternalPrimitiveTypeE code;
 		Boolean[] booleanA = null; 
		Char[] charA = null;
		Double[] doubleA = null;
		Int16[] int16A = null;
 		Int32[] int32A = null; 
		Int64[] int64A = null;
 		SByte[] sbyteA = null; 
 		Single[] singleA = null; 
		UInt16[] uint16A = null;
 		UInt32[] uint32A = null; 
		UInt64[] uint64A = null;


		internal PrimitiveArray(InternalPrimitiveTypeE code, Array array) 
		{
 			Init(code, array); 
		} 

 		internal void Init(InternalPrimitiveTypeE code, Array array) 
 		{
			this.code = code;
 			switch(code)
			{ 
				case InternalPrimitiveTypeE.Boolean:
					booleanA = (Boolean[])array; 
 					break; 
				case InternalPrimitiveTypeE.Char:
 					charA = (Char[])array; 
 					break;					
				case InternalPrimitiveTypeE.Double:
 					doubleA = (Double[])array;
					break;					 
				case InternalPrimitiveTypeE.Int16:
					int16A = (Int16[])array; 
 					break;					 
				case InternalPrimitiveTypeE.Int32:
 					int32A = (Int32[])array; 
 					break;					
				case InternalPrimitiveTypeE.Int64:
 					int64A = (Int64[])array;
					break;					 
				case InternalPrimitiveTypeE.SByte:
					sbyteA = (SByte[])array; 
 					break;					 
				case InternalPrimitiveTypeE.Single:
 					singleA = (Single[])array; 
 					break;					
				case InternalPrimitiveTypeE.UInt16:
 					uint16A = (UInt16[])array;
					break;					 
				case InternalPrimitiveTypeE.UInt32:
					uint32A = (UInt32[])array; 
 					break;					 
				case InternalPrimitiveTypeE.UInt64:
 					uint64A = (UInt64[])array; 
 					break;
			}
 		}
 
		internal String GetValue(int index)
		{ 
			String value = null; 
 			switch(code)
			{ 
 				case InternalPrimitiveTypeE.Boolean:
 					value =  (booleanA[index]).ToString();
					break;
 				case InternalPrimitiveTypeE.Char: 
					if (charA[index] == Char.MinValue)
						value = "_0x00_"; 
					else 
 						value =  Char.ToString(charA[index]);
					break;					 
                case InternalPrimitiveTypeE.Double:
                    if (Double.IsPositiveInfinity(doubleA[index]))
                        value = "INF";
                    else if (Double.IsNegativeInfinity(doubleA[index])) 
                        value = "-INF";
                    else 
                        value =  (doubleA[index]).ToString("R", CultureInfo.InvariantCulture); 
 					break;					
 				case InternalPrimitiveTypeE.Int16: 
					value =  (int16A[index]).ToString(CultureInfo.InvariantCulture);
 					break;					
				case InternalPrimitiveTypeE.Int32:
					value =  (int32A[index]).ToString(CultureInfo.InvariantCulture); 
					break;					
 				case InternalPrimitiveTypeE.Int64: 
					value =  (int64A[index]).ToString(CultureInfo.InvariantCulture); 
 					break;					
 				case InternalPrimitiveTypeE.SByte: 
					value =  (sbyteA[index]).ToString(CultureInfo.InvariantCulture);
 					break;					
                case InternalPrimitiveTypeE.Single:
                    if (Single.IsPositiveInfinity(singleA[index])) 
                        value = "INF";
                    else if (Single.IsNegativeInfinity(singleA[index])) 
                        value = "-INF"; 
                    else
                        value =  (singleA[index]).ToString("R", CultureInfo.InvariantCulture); 
					break;
				case InternalPrimitiveTypeE.UInt16:
					value =  (uint16A[index]).ToString(CultureInfo.InvariantCulture);
 					break; 
				case InternalPrimitiveTypeE.UInt32:
 					value =  (uint32A[index]).ToString(CultureInfo.InvariantCulture); 
 					break;					 
				case InternalPrimitiveTypeE.UInt64:
 					value =  (uint64A[index]).ToString(CultureInfo.InvariantCulture); 
					break;					
			}
			return value;
 		} 

		internal void SetValue(String value, int index) 
 		{ 
 			InternalST.Soap("PrimitiveArray value ", value," index ", index, " code ",((Enum)code).ToString());
			switch(code) 
 			{
				case InternalPrimitiveTypeE.Boolean:
					booleanA[index] = Boolean.Parse(value);
					break; 
 				case InternalPrimitiveTypeE.Char:
					if ((value[0] == '_') && (value.Equals("_0x00_"))) 
 						charA[index] = Char.MinValue; 
 					else
						charA[index] = Char.Parse(value); 
 					break;					
                case InternalPrimitiveTypeE.Double:
                    if (value == "INF")
                        doubleA[index] =  Double.PositiveInfinity; 
                    else if (value == "-INF")
                        doubleA[index] =  Double.NegativeInfinity; 
                    else 
                        doubleA[index] = Double.Parse(value, CultureInfo.InvariantCulture);
					break;					 
				case InternalPrimitiveTypeE.Int16:
					int16A[index] = Int16.Parse(value, CultureInfo.InvariantCulture);															
 					break;					
				case InternalPrimitiveTypeE.Int32: 
 					int32A[index] = Int32.Parse(value, CultureInfo.InvariantCulture);																				
 					break;					 
				case InternalPrimitiveTypeE.Int64: 
 					int64A[index] = Int64.Parse(value, CultureInfo.InvariantCulture);																									
					break;					 
				case InternalPrimitiveTypeE.SByte:
					sbyteA[index] = SByte.Parse(value, CultureInfo.InvariantCulture);
 					break;					
                case InternalPrimitiveTypeE.Single: 
                    if (value == "INF")
                        singleA[index] =  Single.PositiveInfinity; 
                    else if (value == "-INF") 
                        singleA[index] =  Single.NegativeInfinity;
                    else 
                        singleA[index] = Single.Parse(value, CultureInfo.InvariantCulture);
					break;
 				case InternalPrimitiveTypeE.UInt16:
 					uint16A[index] = UInt16.Parse(value, CultureInfo.InvariantCulture); 
					break;
 				case InternalPrimitiveTypeE.UInt32: 
					uint32A[index] = UInt32.Parse(value, CultureInfo.InvariantCulture);					 
					break;					
				case InternalPrimitiveTypeE.UInt64: 
 					uint64A[index] = UInt64.Parse(value, CultureInfo.InvariantCulture);					
					break;					
 			}
 		} 
	}
} 
 

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK