コード例 #1
0
        SerializableType CompileNonContractTypes(Type type)
        {
            // built-in type
            Encode encoder;
            Decode decoder;

            if (Encoder.TryGetCodec(type, out encoder, out decoder))
            {
                return(SerializableType.CreatePrimitiveType(type, encoder, decoder));
            }

            if (type == typeof(object))
            {
                return(SerializableType.CreateObjectType(type));
            }

            if (typeof(Described).IsAssignableFrom(type))
            {
                return(SerializableType.CreateObjectType(type));
            }

            if (typeof(IAmqpSerializable).IsAssignableFrom(type))
            {
                return(SerializableType.CreateAmqpSerializableType(this, type));
            }

            if (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                Type[] argTypes = type.GetGenericArguments();
                Fx.Assert(argTypes.Length == 1, "Nullable type must have one argument");
                Type argType = argTypes[0];
                if (argType.IsEnum())
                {
                    return(CompileEnumType(argType));
                }
                else
                {
                    return(SerializableType.CreateObjectType(type));
                }
            }

            if (type.IsEnum())
            {
                return(CompileEnumType(type));
            }

            SerializableType collection = this.CompileCollectionTypes(type);

            if (collection != null)
            {
                return(collection);
            }

            return(null);
        }
コード例 #2
0
        SerializableType CompileNonContractTypes(Type type)
        {
            // built-in type
            Encode encoder;
            Decode decoder;

            if (Encoder.TryGetCodec(type, out encoder, out decoder))
            {
                return(SerializableType.CreatePrimitiveType(type, encoder, decoder));
            }

            if (type == typeof(object))
            {
                return(SerializableType.CreateObjectType(type));
            }

            if (typeof(IAmqpSerializable).IsAssignableFrom(type))
            {
                return(SerializableType.CreateAmqpSerializableType(this, type));
            }

            if (typeof(Described).IsAssignableFrom(type))
            {
                return(SerializableType.CreateAmqpDescribedType(this, type));
            }

            SerializableType nullable = this.CompileNullableTypes(type);

            if (nullable != null)
            {
                return(nullable);
            }

            SerializableType collection = this.CompileCollectionTypes(type);

            if (collection != null)
            {
                return(collection);
            }

            return(null);
        }