示例#1
0
        public void RecursiveArrayClass()
        {
            Type       type    = typeof(ExampleWithArray);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType);
        }
示例#2
0
        public void StructWithEnum()
        {
            Type       type    = typeof(struct2);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType,
                            "struct doesn't map to XmlRpcType.tInvalid");
        }
示例#3
0
        public void DBNull()
        {
            DBNull     value   = System.DBNull.Value;
            Type       type    = value.GetType();
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType,
                            "GetXmlRpcType return DBNull as tStruct");
        }
示例#4
0
 private void CheckImplictString(Type valType, MappingStack mappingStack)
 {
     if (valType == null || valType == typeof(string) || valType.IsEnum)
     {
         return;
     }
     throw new XmlRpcTypeMismatchException(mappingStack.MappingType + " contains implicit string value where " +
                                           XmlRpcTypeInfo.GetXmlRpcTypeString(valType) + " expected " +
                                           StackDump(mappingStack));
 }
示例#5
0
        public void JaggedIntArray()
        {
            Type       type    = typeof(Int32[][]);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tArray, rpcType,
                            "Int32[] doesn't map to XmlRpcType.tArray");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "array", "Int32[] doesn't map to 'array'");
        }
示例#6
0
        public void Array()
        {
            Type       type    = typeof(Array);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tArray, rpcType,
                            "Array doesn't map to XmlRpcType.tArray");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "array", "Array doesn't map to 'array'");
        }
示例#7
0
        public void Base64()
        {
            Type       type    = typeof(byte[]);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tBase64, rpcType,
                            "Byte[] doesn't map to XmlRpcType.tBase64");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "base64", "Byte[] doesn't map to 'base64'");
        }
示例#8
0
        public void Int32()
        {
            Type       type    = typeof(int);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInt32, rpcType,
                            "Int32 doesn't map to XmlRpcType.tInt32");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "integer", "Int32 doesn't map to 'integer'");
        }
示例#9
0
 public void EnumXmlRpcType()
 {
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(ByteEnum)), "byte");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(SByteEnum)), "sbyte");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(ShortEnum)), "short");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(UShortEnum)), "ushort");
     Assert.AreEqual(XmlRpcType.tInt32, XmlRpcTypeInfo.GetXmlRpcType(typeof(IntEnum)), "int");
     Assert.AreEqual(XmlRpcType.tInt64, XmlRpcTypeInfo.GetXmlRpcType(typeof(UIntEnum)), "uint");
     Assert.AreEqual(XmlRpcType.tInt64, XmlRpcTypeInfo.GetXmlRpcType(typeof(LongEnum)), "long");
     Assert.AreEqual(XmlRpcType.tInvalid, XmlRpcTypeInfo.GetXmlRpcType(typeof(ULongEnum)), "ulong");
 }
示例#10
0
        public void Int64()
        {
            Type       type    = typeof(long);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tInt64, rpcType,
                            "Int64 doesn't map to XmlRpcType.tInt64");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "i8", "Int64 doesn't map to 'i8'");
        }
示例#11
0
        public void Void()
        {
            Type       type    = typeof(void);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tVoid, rpcType,
                            "void doesn't map to XmlRpcType.tVoid");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "void", "void doesn't map to 'void'");
        }
示例#12
0
        public void Double()
        {
            Type       type    = typeof(double);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDouble, rpcType,
                            "Double doesn't map to XmlRpcType.tDouble");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "double", "Double doesn't map to 'double'");
        }
示例#13
0
        public void String()
        {
            Type       type    = typeof(string);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tString, rpcType,
                            "String doesn't map to XmlRpcType.tString");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "string", "String doesn't map to 'string'");
        }
示例#14
0
        public void XmlRpcBoolean()
        {
            Type       type    = typeof(bool?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tBoolean, rpcType,
                            "XmlRpcBoolean doesn't map to XmlRpcType.tBoolean");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "boolean",
                            "XmlRpcBoolean doesn't map to 'boolean'");
        }
示例#15
0
        public void NullableStruct()
        {
            Type       type    = typeof(TestStruct?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tStruct, rpcType,
                            "TestStruct? doesn't map to XmlRpcType.tStruct");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "struct",
                            "TestStruct? doesn't map to 'struct'");
        }
示例#16
0
        public void NullableDateTime()
        {
            Type       type    = typeof(DateTime?);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tDateTime, rpcType,
                            "DateTime? doesn't map to XmlRpcType.tDateTime");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "dateTime",
                            "DateTime? doesn't map to 'dateTime'");
        }
示例#17
0
        public void XmlRpcStruct()
        {
            Type       type    = typeof(XmlRpcStruct);
            XmlRpcType rpcType = XmlRpcTypeInfo.GetXmlRpcType(type);

            Assert.AreEqual(XmlRpcType.tHashtable, rpcType,
                            "XmlRpcStruct doesn't map to XmlRpcType.tHashtable");
            string rpcString = XmlRpcTypeInfo.GetXmlRpcTypeString(type);

            Assert.AreEqual(rpcString, "struct",
                            "XmlRpcStruct doesn't map to 'struct'");
        }
示例#18
0
 private void CheckExpectedType(Type expectedType, Type actualType, MappingStack mappingStack)
 {
     if (expectedType != null && expectedType.IsEnum)
     {
         var array1 = new[]
         {
             typeof(byte),
             typeof(sbyte),
             typeof(short),
             typeof(ushort),
             typeof(int)
         };
         var array2 = new[]
         {
             typeof(uint),
             typeof(long)
         };
         Type underlyingType = Enum.GetUnderlyingType(expectedType);
         if (Array.IndexOf(array1, underlyingType) >= 0)
         {
             expectedType = typeof(int);
         }
         else if (Array.IndexOf(array2, underlyingType) >= 0)
         {
             expectedType = typeof(long);
         }
         else
         {
             throw new XmlRpcInvalidEnumValue(mappingStack.MappingType + " contains " +
                                              XmlRpcTypeInfo.GetXmlRpcTypeString(actualType) +
                                              " which cannot be mapped to  " +
                                              XmlRpcTypeInfo.GetXmlRpcTypeString(expectedType) + " " +
                                              StackDump(mappingStack));
         }
     }
     if (expectedType == null || expectedType == typeof(object) ||
         (expectedType == actualType || !actualType.IsValueType))
     {
         return;
     }
     if (expectedType == typeof(Nullable <>).MakeGenericType(new Type[]
     {
         actualType
     }))
     {
         return;
     }
     throw new XmlRpcTypeMismatchException(mappingStack.MappingType + " contains " +
                                           XmlRpcTypeInfo.GetXmlRpcTypeString(actualType) + " value where " +
                                           XmlRpcTypeInfo.GetXmlRpcTypeString(expectedType) + " expected " +
                                           StackDump(mappingStack));
 }
示例#19
0
        private object MapStruct(IEnumerator <Node> iter, Type valueType, MappingStack mappingStack,
                                 MappingAction mappingAction, out Type mappedType)
        {
            mappedType = null;
            if (valueType.IsPrimitive)
            {
                throw new XmlRpcTypeMismatchException(mappingStack.MappingType + " contains struct value where " +
                                                      XmlRpcTypeInfo.GetXmlRpcTypeString(valueType) + " expected " +
                                                      StackDump(mappingStack));
            }
            if (valueType.IsGenericType)
            {
                if (valueType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    valueType = valueType.GetGenericArguments()[0];
                }
            }
            object instance;

            try
            {
                instance = Activator.CreateInstance(valueType);
            }
            catch (Exception ex)
            {
                throw new XmlRpcTypeMismatchException(mappingStack.MappingType + " contains struct value where " +
                                                      XmlRpcTypeInfo.GetXmlRpcTypeString(valueType) +
                                                      " expected (as type " + valueType.Name + ") " +
                                                      StackDump(mappingStack));
            }
            MappingAction mappingAction1 = mappingAction;

            if (valueType != null)
            {
                (mappingStack).Push("struct mapped to type " + valueType.Name);
                mappingAction1 = StructMappingAction(valueType, mappingAction);
            }
            else
            {
                (mappingStack).Push("struct");
            }
            List <string> names = new List <string>();

            CreateFieldNamesMap(valueType, names);
            int           num  = 0;
            List <string> list = new List <string>();

            try
            {
                while (iter.MoveNext())
                {
                    if (iter.Current is StructMember)
                    {
                        string XmlRpcName = (iter.Current as StructMember).Value;
                        if (list.Contains(XmlRpcName))
                        {
                            if (!IgnoreDuplicateMembers)
                            {
                                throw new XmlRpcInvalidXmlRpcException(mappingStack.MappingType +
                                                                       " contains struct value with duplicate member " +
                                                                       XmlRpcName + " " + StackDump(mappingStack));
                            }
                        }
                        else
                        {
                            list.Add(XmlRpcName);
                            string     name    = GetStructName(valueType, XmlRpcName) ?? XmlRpcName;
                            MemberInfo element = valueType.GetField(name) ??
                                                 (MemberInfo)valueType.GetProperty(name);
                            if (element == null)
                            {
                                iter.MoveNext();
                                //If this is a table object, then we need to populate
                                // the value in the custom fields dictionary.
                                if (valueType.IsSubclassOf(typeof(Table)))
                                {
                                    AddCustomField(iter, mappingStack, mappingAction, name, instance);
                                }
                                if (iter.Current is ComplexValueNode)
                                {
                                    int depth = iter.Current.Depth;
                                    while (!(iter.Current is EndComplexValueNode) || iter.Current.Depth != depth)
                                    {
                                        iter.MoveNext();
                                    }
                                }
                            }
                            else
                            {
                                if (names.Contains(name))
                                {
                                    names.Remove(name);
                                }
                                else if (Attribute.IsDefined(element, typeof(NonSerializedAttribute)))
                                {
                                    (mappingStack).Push(string.Format("member {0}", name));
                                    throw new XmlRpcNonSerializedMember(
                                              "Cannot map XML-RPC struct member onto member marked as [NonSerialized]:  " +
                                              StackDump(mappingStack));
                                }
                                Type memberType = element.MemberType == MemberTypes.Field
                                                      ? (element as FieldInfo).FieldType
                                                      : (element as PropertyInfo).PropertyType;
                                string p = valueType == null
                                               ? string.Format("member {0}", name)
                                               : string.Format("member {0} mapped to type {1}", name,
                                                               memberType.Name);

                                iter.MoveNext();
                                object obj = OnStack(p, mappingStack,
                                                     (() =>
                                                      MapValueNode(iter, memberType, mappingStack, mappingAction)));
                                if (element.MemberType == MemberTypes.Field)
                                {
                                    (element as FieldInfo).SetValue(instance, obj);
                                }
                                else
                                {
                                    (element as PropertyInfo).SetValue(instance, obj, null);
                                }
                                ++num;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (mappingAction1 == MappingAction.Error && names.Count > 0)
                {
                    ReportMissingMembers(valueType, names, mappingStack);
                }
                return(instance);
            }
            finally
            {
                mappingStack.Pop();
            }
        }
示例#20
0
        private object MapArray(IEnumerator <Node> iter, Type valType, MappingStack mappingStack,
                                MappingAction mappingAction, out Type mappedType)
        {
            mappedType = null;
            if (valType != null && !valType.IsArray && (valType != typeof(Array) && valType != typeof(object)))
            {
                throw new XmlRpcTypeMismatchException(mappingStack.MappingType + " contains array value where " +
                                                      XmlRpcTypeInfo.GetXmlRpcTypeString(valType) + " expected " +
                                                      StackDump(mappingStack));
            }
            if (valType != null)
            {
                if (XmlRpcTypeInfo.GetXmlRpcType(valType) == XmlRpcType.tMultiDimArray)
                {
                    (mappingStack).Push("array mapped to type " + valType.Name);
                    return(MapMultiDimArray(iter, valType, mappingStack, mappingAction));
                }
                else
                {
                    (mappingStack).Push("array mapped to type " + valType.Name);
                }
            }
            else
            {
                (mappingStack).Push("array");
            }
            List <object> list        = new List <object>();
            Type          valType1    = DetermineArrayItemType(valType);
            bool          flag        = false;
            Type          elementType = null;

            while (iter.MoveNext() && iter.Current is ValueNode)
            {
                (mappingStack).Push(string.Format("element {0}", list.Count));
                object obj = MapValueNode(iter, valType1, mappingStack, mappingAction);
                list.Add(obj);
                mappingStack.Pop();
            }
            foreach (object obj in list)
            {
                if (obj != null)
                {
                    if (!flag)
                    {
                        elementType = obj.GetType();
                        flag        = true;
                    }
                    else if (elementType != obj.GetType())
                    {
                        elementType = null;
                    }
                }
            }
            object[] args = new object[1]
            {
                list.Count
            };
            object obj1 = valType == null || valType == typeof(Array) || valType == typeof(object)
                              ? (elementType != null
                                     ? Array.CreateInstance(elementType, (int)args[0])
                                     : CreateArrayInstance(typeof(object[]), args))
                              : CreateArrayInstance(valType, args);

            for (int index = 0; index < list.Count; ++index)
            {
                ((Array)obj1).SetValue(list[index], index);
            }
            mappingStack.Pop();
            return(obj1);
        }