예제 #1
0
 /// <summary>
 /// Indicates that while an inheritance tree exists, the exact type encountered was not
 /// specified in that hierarchy and cannot be processed.
 /// </summary>
 protected internal static void ThrowUnexpectedSubtype(Type expected, Type actual)
 {
     if (expected != TypeModel.ResolveProxies(actual))
     {
         throw new InvalidOperationException("Unexpected sub-type: " + actual.FullName);
     }
 }
예제 #2
0
        internal MetaType FindWithoutAdd(Type type)
        {
            BasicList.NodeEnumerator enumerator = this.types.GetEnumerator();
            while (enumerator.MoveNext())
            {
                MetaType metaType = (MetaType)enumerator.Current;
                if (metaType.Type == type)
                {
                    if (metaType.Pending)
                    {
                        this.WaitOnLock(metaType);
                    }
                    return(metaType);
                }
            }
            Type type2 = TypeModel.ResolveProxies(type);

            return((type2 != null) ? this.FindWithoutAdd(type2) : null);
        }
        // Token: 0x0600036D RID: 877 RVA: 0x00012CF0 File Offset: 0x00010EF0
        internal MetaType FindWithoutAdd(Type type)
        {
            foreach (object obj in this.types)
            {
                MetaType metaType = (MetaType)obj;
                if (metaType.Type == type)
                {
                    if (metaType.Pending)
                    {
                        this.WaitOnLock(metaType);
                    }
                    return(metaType);
                }
            }
            Type type2 = TypeModel.ResolveProxies(type);

            if (type2 != null)
            {
                return(this.FindWithoutAdd(type2));
            }
            return(null);
        }
        // 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);
        }