// Token: 0x06000371 RID: 881 RVA: 0x00012D84 File Offset: 0x00010F84
        internal IProtoSerializer TryGetBasicTypeSerializer(Type type)
        {
            int num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);

            if (num >= 0)
            {
                return(((RuntimeTypeModel.BasicType) this.basicTypes[num]).Serializer);
            }
            BasicList        obj = this.basicTypes;
            IProtoSerializer result;

            lock (obj)
            {
                num = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type);
                if (num >= 0)
                {
                    result = ((RuntimeTypeModel.BasicType) this.basicTypes[num]).Serializer;
                }
                else
                {
                    WireType         wireType;
                    IProtoSerializer protoSerializer = (MetaType.GetContractFamily(this, type, null) == MetaType.AttributeFamily.None) ? ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType, false, false, false, false) : null;
                    if (protoSerializer != null)
                    {
                        this.basicTypes.Add(new RuntimeTypeModel.BasicType(type, protoSerializer));
                    }
                    result = protoSerializer;
                }
            }
            return(result);
        }
        internal int FindOrAddAuto(Type type, bool demand, bool addWithContractOnly, bool addEvenIfAutoDisabled)
        {
            TypeFinder predicate = new TypeFinder(type);
            int        key       = types.IndexOf(predicate);

            if (key < 0)
            {
                // check for proxy types
                Type underlyingType = ResolveProxies(type);
                if (underlyingType != null)
                {
                    predicate = new TypeFinder(underlyingType);
                    key       = types.IndexOf(predicate);
                    type      = underlyingType; // if new added, make it reflect the underlying type
                }
            }

            if (key < 0)
            {
                MetaType metaType;
                // try to recognise a few familiar patterns...
                if ((metaType = RecogniseCommonTypes(type)) == null)
                { // otherwise, check if it is a contract
                    bool shouldAdd = autoAddMissingTypes || addEvenIfAutoDisabled;
                    if (!shouldAdd || (
                            addWithContractOnly && MetaType.GetContractFamily(type, null) == MetaType.AttributeFamily.None)
                        )
                    {
                        if (demand)
                        {
                            ThrowUnexpectedType(type);
                        }
                        return(key);
                    }
                    metaType = Create(type);
                }

                bool weAdded = false;
                lock (types)
                {   // double-checked
                    int winner = types.IndexOf(predicate);
                    if (winner < 0)
                    {
                        ThrowIfFrozen();
                        key     = types.Add(metaType);
                        weAdded = true;
                    }
                    else
                    {
                        key = winner;
                    }
                }
                if (weAdded)
                {
                    metaType.ApplyDefaultBehaviour();
                }
            }
            return(key);
        }
        // Token: 0x06000372 RID: 882 RVA: 0x00012E4C File Offset: 0x0001104C
        internal int FindOrAddAuto(Type type, bool demand, bool addWithContractOnly, bool addEvenIfAutoDisabled)
        {
            int num = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type);

            if (num >= 0)
            {
                MetaType metaType = (MetaType)this.types[num];
                if (metaType.Pending)
                {
                    this.WaitOnLock(metaType);
                }
                return(num);
            }
            bool flag = this.AutoAddMissingTypes || addEvenIfAutoDisabled;

            if (Helpers.IsEnum(type) || this.TryGetBasicTypeSerializer(type) == null)
            {
                Type type2 = TypeModel.ResolveProxies(type);
                if (type2 != null)
                {
                    num  = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type2);
                    type = type2;
                }
                if (num < 0)
                {
                    int opaqueToken = 0;
                    try
                    {
                        this.TakeLock(ref opaqueToken);
                        MetaType metaType;
                        if ((metaType = this.RecogniseCommonTypes(type)) == null)
                        {
                            MetaType.AttributeFamily contractFamily = MetaType.GetContractFamily(this, type, null);
                            if (contractFamily == MetaType.AttributeFamily.AutoTuple)
                            {
                                addEvenIfAutoDisabled = (flag = true);
                            }
                            if (!flag || (!Helpers.IsEnum(type) && addWithContractOnly && contractFamily == MetaType.AttributeFamily.None))
                            {
                                if (demand)
                                {
                                    TypeModel.ThrowUnexpectedType(type);
                                }
                                return(num);
                            }
                            metaType = this.Create(type);
                        }
                        metaType.Pending = true;
                        bool flag2 = false;
                        int  num2  = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type);
                        if (num2 < 0)
                        {
                            this.ThrowIfFrozen();
                            num   = this.types.Add(metaType);
                            flag2 = true;
                        }
                        else
                        {
                            num = num2;
                        }
                        if (flag2)
                        {
                            metaType.ApplyDefaultBehaviour();
                            metaType.Pending = false;
                        }
                    }
                    finally
                    {
                        this.ReleaseLock(opaqueToken);
                    }
                    return(num);
                }
                return(num);
            }
            if (flag && !addWithContractOnly)
            {
                throw MetaType.InbuiltType(type);
            }
            return(-1);
        }
Exemple #4
0
        internal int FindOrAddAuto(Type type, bool demand, bool addWithContractOnly, bool addEvenIfAutoDisabled)
        {
            TypeFinder predicate = new TypeFinder(type);
            int        key       = types.IndexOf(predicate);
            MetaType   metaType;

            if (key >= 0 && (metaType = ((MetaType)types[key])).Pending)
            {
                WaitOnLock(metaType);
            }
            if (key < 0)
            {
                // check for proxy types
                Type underlyingType = ResolveProxies(type);
                if (underlyingType != null)
                {
                    predicate = new TypeFinder(underlyingType);
                    key       = types.IndexOf(predicate);
                    type      = underlyingType; // if new added, make it reflect the underlying type
                }
            }

            if (key < 0)
            {
                bool lockTaken = false;
                try
                {
                    TakeLock(ref lockTaken);
                    // try to recognise a few familiar patterns...
                    if ((metaType = RecogniseCommonTypes(type)) == null)
                    { // otherwise, check if it is a contract
                        MetaType.AttributeFamily family = MetaType.GetContractFamily(type, null);
                        if (family == MetaType.AttributeFamily.AutoTuple)
                        {
                            addEvenIfAutoDisabled = true;                                               // always add basic tuples, such as KeyValuePair
                        }
                        bool shouldAdd = AutoAddMissingTypes || addEvenIfAutoDisabled;
                        if (!shouldAdd || (
                                !type.IsEnum && addWithContractOnly && family == MetaType.AttributeFamily.None)
                            )
                        {
                            if (demand)
                            {
                                ThrowUnexpectedType(type);
                            }
                            return(key);
                        }
                        metaType = Create(type);
                    }
                    metaType.Pending = true;
                    bool weAdded = false;

                    // double-checked
                    int winner = types.IndexOf(predicate);
                    if (winner < 0)
                    {
                        ThrowIfFrozen();
                        key     = types.Add(metaType);
                        weAdded = true;
                    }
                    else
                    {
                        key = winner;
                    }
                    if (weAdded)
                    {
                        metaType.ApplyDefaultBehaviour();
                        metaType.Pending = false;
                    }
                }
                finally
                {
                    ReleaseLock(lockTaken);
                }
            }
            return(key);
        }