예제 #1
0
 protected void SetUp()
 {
     testSerializerOperationMap       = new SerializerOperationMap();
     TestXmlSerializationOperation1   = XmlSerialize1;
     TestXmlDeserializationOperation1 = XmlDeserialize1;
     TestXmlSerializationOperation2   = XmlSerialize2;
     TestXmlDeserializationOperation2 = XmlDeserialize2;
 }
예제 #2
0
        public void GetSerializationOperationTypeExists()
        {
            testSerializerOperationMap.AddMapping(typeof(System.String), "string", TestXmlSerializationOperation1, TestXmlDeserializationOperation1);
            testSerializerOperationMap.AddMapping(typeof(System.Decimal), "long", TestXmlSerializationOperation2, TestXmlDeserializationOperation2);
            XmlSerializationOperation returnedOperation = testSerializerOperationMap.GetSerializationOperation(typeof(System.String));

            Assert.AreEqual(TestXmlSerializationOperation1, returnedOperation);
        }
예제 #3
0
        public void GetSerializationOperationTypeDoesNotExist()
        {
            testSerializerOperationMap.AddMapping(typeof(System.String), "string", TestXmlSerializationOperation1, TestXmlDeserializationOperation1);
            testSerializerOperationMap.AddMapping(typeof(System.Decimal), "long", TestXmlSerializationOperation2, TestXmlDeserializationOperation2);
            XmlSerializationOperation returnedOperation = testSerializerOperationMap.GetSerializationOperation(typeof(System.DateTime));

            Assert.IsNull(returnedOperation);
        }
예제 #4
0
        public void UpdateMappingSuccessTests()
        {
            testSerializerOperationMap.AddMapping(typeof(System.String), "string", TestXmlSerializationOperation1, TestXmlDeserializationOperation1);
            testSerializerOperationMap.AddMapping(typeof(System.Int32), "integer", TestXmlSerializationOperation2, TestXmlDeserializationOperation2);
            testSerializerOperationMap.UpdateMapping(typeof(System.String), "UpdatedString", TestXmlSerializationOperation2, TestXmlDeserializationOperation2);
            XmlSerializationOperation   returnedSerializationOperation   = testSerializerOperationMap.GetSerializationOperation(typeof(System.String));
            XmlDeserializationOperation returnedDeserializationOperation = testSerializerOperationMap.GetDeserializationOperation("UpdatedString");

            Assert.AreEqual("UpdatedString", testSerializerOperationMap.GetSerializedType(typeof(System.String)));
            Assert.AreEqual(TestXmlSerializationOperation2, returnedSerializationOperation);
            Assert.AreEqual(TestXmlDeserializationOperation2, returnedDeserializationOperation);
        }
예제 #5
0
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.ISerializerOperationMap.UpdateMapping(System.Type,System.String,MethodInvocationRemoting.XmlSerializationOperation,MethodInvocationRemoting.XmlDeserializationOperation)"]/*'/>
        public void UpdateMapping(Type nativeType, string serializedType, XmlSerializationOperation serializationOperation, XmlDeserializationOperation deserializationOperation)
        {
            // Check for null parameters
            CheckAddUpdateParameters(nativeType, serializedType, serializationOperation, deserializationOperation);

            // Check that the mapping already exists
            if (nativeToSerializedMap.ContainsKey(nativeType) == false)
            {
                throw new ArgumentException("The native type '" + nativeType.FullName + "' does not exist in the map.", "nativeType");
            }

            // Remove the existing mapping
            serializedToNativeMap.Remove(serializedType);
            nativeToSerializedMap.Remove(nativeType);

            // Add the new mapping
            AddMapping(nativeType, serializedType, serializationOperation, deserializationOperation);
        }
예제 #6
0
        /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:MethodInvocationRemoting.ISerializerOperationMap.AddMapping(System.Type,System.String,MethodInvocationRemoting.XmlSerializationOperation,MethodInvocationRemoting.XmlDeserializationOperation)"]/*'/>
        public void AddMapping(Type nativeType, string serializedType, XmlSerializationOperation serializationOperation, XmlDeserializationOperation deserializationOperation)
        {
            // Check for null parameters
            CheckAddUpdateParameters(nativeType, serializedType, serializationOperation, deserializationOperation);

            // Check for attempt to add duplicate entry
            if (serializedToNativeMap.ContainsKey(serializedType) == true)
            {
                throw new ArgumentException("The serialized type '" + serializedType + "' already exists in the map.", "serializedType");
            }
            if (nativeToSerializedMap.ContainsKey(nativeType) == true)
            {
                throw new ArgumentException("The native type '" + nativeType.FullName + "' already exists in the map.", "nativeType");
            }

            // Add the mapping
            serializedToNativeMap.Add(serializedType, new NativeTypeSerialisationOperationsMap(nativeType, serializationOperation, deserializationOperation));
            nativeToSerializedMap.Add(nativeType, new SerializedTypeSerialisationOperationsMap(serializedType, serializationOperation, deserializationOperation));
        }
예제 #7
0
 /// <summary>
 /// Initialises a new instance of the MethodInvocationRemoting.SerializedTypeSerialisationOperationsMap structure.
 /// </summary>
 /// <param name="serializedType">The string representation of the type in the mapping.</param>
 /// <param name="xmlSerializationOperation">The method used to serialize objects of the type.</param>
 /// <param name="xmlDeserializationOperation">The method used to deserialize objects of the type.</param>
 public SerializedTypeSerialisationOperationsMap(string serializedType, XmlSerializationOperation xmlSerializationOperation, XmlDeserializationOperation xmlDeserializationOperation)
 {
     this.serializedType              = serializedType;
     this.xmlSerializationOperation   = xmlSerializationOperation;
     this.xmlDeserializationOperation = xmlDeserializationOperation;
 }
예제 #8
0
 /// <summary>
 /// Initialises a new instance of the MethodInvocationRemoting.NativeTypeSerialisationOperationsMap structure.
 /// </summary>
 /// <param name="nativeType">The native .NET type in the mapping.</param>
 /// <param name="xmlSerializationOperation">The method used to serialize objects of the type.</param>
 /// <param name="xmlDeserializationOperation">The method used to deserialize objects of the type.</param>
 public NativeTypeSerialisationOperationsMap(Type nativeType, XmlSerializationOperation xmlSerializationOperation, XmlDeserializationOperation xmlDeserializationOperation)
 {
     this.nativeType = nativeType;
     this.xmlSerializationOperation   = xmlSerializationOperation;
     this.xmlDeserializationOperation = xmlDeserializationOperation;
 }
예제 #9
0
 //------------------------------------------------------------------------------
 //
 // Method: CheckAddUpdateParameters
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Checks the inputted parameters, and throws an exception if any are null.
 /// </summary>
 /// <param name="nativeType">The native .NET type in the mapping.</param>
 /// <param name="serializedType">A string representation of the type.</param>
 /// <param name="serializationOperation">A method which serializes objects of the type.</param>
 /// <param name="deserializationOperation">A method which deserializes objects of the type.</param>
 private void CheckAddUpdateParameters(Type nativeType, string serializedType, XmlSerializationOperation serializationOperation, XmlDeserializationOperation deserializationOperation)
 {
     if (nativeType == null)
     {
         throw new ArgumentNullException("nativeType", "Parameter 'nativeType' cannot be null.");
     }
     if (serializedType == null)
     {
         throw new ArgumentNullException("serializedType", "Parameter 'serializedType' cannot be null.");
     }
     if (serializationOperation == null)
     {
         throw new ArgumentNullException("serializationOperation", "Parameter 'serializationOperation' cannot be null.");
     }
     if (deserializationOperation == null)
     {
         throw new ArgumentNullException("deserializationOperation", "Parameter 'deserializationOperation' cannot be null.");
     }
 }