// 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);
        }