private SerializableType CompileType(Type type, bool describedOnly)
        {
            int valueOrDefault;

            object[] customAttributes = type.GetCustomAttributes(typeof(AmqpContractAttribute), false);
            if ((int)customAttributes.Length == 0)
            {
                if (describedOnly)
                {
                    return(null);
                }
                return(this.CompileNonContractTypes(type));
            }
            AmqpContractAttribute amqpContractAttribute = (AmqpContractAttribute)customAttributes[0];
            SerializableType      serializableType      = null;

            if (type.BaseType != typeof(object))
            {
                serializableType = this.CompileType(type.BaseType, true);
                if (serializableType != null)
                {
                    if (serializableType.Encoding != amqpContractAttribute.Encoding)
                    {
                        throw new SerializationException(SRAmqp.AmqpEncodingTypeMismatch(type.Name, amqpContractAttribute.Encoding, type.BaseType.Name, serializableType.Encoding));
                    }
                    this.customTypeCache.TryAdd(type.BaseType, serializableType);
                }
            }
            string name         = amqpContractAttribute.Name;
            ulong? internalCode = amqpContractAttribute.InternalCode;

            if (name == null && !internalCode.HasValue)
            {
                name = type.FullName;
            }
            List <SerialiableMember> serialiableMembers = new List <SerialiableMember>();

            if (amqpContractAttribute.Encoding == EncodingType.List && serializableType != null)
            {
                serialiableMembers.AddRange(serializableType.Members);
            }
            int count = serialiableMembers.Count + 1;

            MemberInfo[]   members        = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            MethodAccessor methodAccessor = null;

            MemberInfo[] memberInfoArray = members;
            for (int i = 0; i < (int)memberInfoArray.Length; i++)
            {
                MemberInfo memberInfo = memberInfoArray[i];
                if (memberInfo.DeclaringType == type)
                {
                    if (memberInfo.MemberType == MemberTypes.Field || memberInfo.MemberType == MemberTypes.Property)
                    {
                        object[] objArray = memberInfo.GetCustomAttributes(typeof(AmqpMemberAttribute), true);
                        if ((int)objArray.Length == 1)
                        {
                            AmqpMemberAttribute amqpMemberAttribute = (AmqpMemberAttribute)objArray[0];
                            SerialiableMember   serialiableMember   = new SerialiableMember()
                            {
                                Name = amqpMemberAttribute.Name ?? memberInfo.Name
                            };
                            SerialiableMember serialiableMember1 = serialiableMember;
                            int?internalOrder = amqpMemberAttribute.InternalOrder;
                            if (internalOrder.HasValue)
                            {
                                valueOrDefault = internalOrder.GetValueOrDefault();
                            }
                            else
                            {
                                valueOrDefault = count;
                                count          = valueOrDefault + 1;
                            }
                            serialiableMember1.Order    = valueOrDefault;
                            serialiableMember.Mandatory = amqpMemberAttribute.Mandatory;
                            serialiableMember.Accessor  = MemberAccessor.Create(memberInfo, true);
                            serialiableMember.Type      = this.GetType((memberInfo.MemberType == MemberTypes.Field ? ((FieldInfo)memberInfo).FieldType : ((PropertyInfo)memberInfo).PropertyType));
                            serialiableMembers.Add(serialiableMember);
                        }
                    }
                    else if (memberInfo.MemberType == MemberTypes.Method && (int)memberInfo.GetCustomAttributes(typeof(OnDeserializedAttribute), false).Length == 1)
                    {
                        methodAccessor = MethodAccessor.Create((MethodInfo)memberInfo);
                    }
                }
            }
            if (amqpContractAttribute.Encoding == EncodingType.List)
            {
                serialiableMembers.Sort(AmqpContractSerializer.MemberOrderComparer.Instance);
                int order = -1;
                foreach (SerialiableMember serialiableMember2 in serialiableMembers)
                {
                    if (order > 0 && serialiableMember2.Order == order)
                    {
                        throw new SerializationException(SRAmqp.AmqpDuplicateMemberOrder(order, type.Name));
                    }
                    order = serialiableMember2.Order;
                }
            }
            SerialiableMember[] array = serialiableMembers.ToArray();
            Dictionary <Type, SerializableType> types = null;

            object[] customAttributes1 = type.GetCustomAttributes(typeof(KnownTypeAttribute), false);
            for (int j = 0; j < (int)customAttributes1.Length; j++)
            {
                KnownTypeAttribute knownTypeAttribute = (KnownTypeAttribute)customAttributes1[j];
                if ((int)knownTypeAttribute.Type.GetCustomAttributes(typeof(AmqpContractAttribute), false).Length > 0)
                {
                    if (types == null)
                    {
                        types = new Dictionary <Type, SerializableType>();
                    }
                    types.Add(knownTypeAttribute.Type, null);
                }
            }
            if (amqpContractAttribute.Encoding == EncodingType.List)
            {
                return(SerializableType.CreateDescribedListType(this, type, serializableType, name, internalCode, array, types, methodAccessor));
            }
            if (amqpContractAttribute.Encoding != EncodingType.Map)
            {
                throw new NotSupportedException(amqpContractAttribute.Encoding.ToString());
            }
            return(SerializableType.CreateDescribedMapType(this, type, serializableType, name, internalCode, array, types, methodAccessor));
        }