internal IProtoSerializer TryGetBasicTypeSerializer(Type type) { int idx = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type); if (idx >= 0) { return(((RuntimeTypeModel.BasicType) this.basicTypes[idx]).Serializer); } IProtoSerializer result; lock (this.basicTypes) { idx = this.basicTypes.IndexOf(RuntimeTypeModel.BasicTypeFinder, type); if (idx >= 0) { result = ((RuntimeTypeModel.BasicType) this.basicTypes[idx]).Serializer; } else { MetaType.AttributeFamily family = MetaType.GetContractFamily(this, type, null); WireType defaultWireType; IProtoSerializer ser = (family == MetaType.AttributeFamily.None) ? ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType, false, false, false, false) : null; if (ser != null) { this.basicTypes.Add(new RuntimeTypeModel.BasicType(type, ser)); } result = ser; } } return(result); }
// 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); }
public bool HasFamily(MetaType.AttributeFamily value) { return((Family & value) == value); }
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); }
internal int FindOrAddAuto(Type type, bool demand, bool addWithContractOnly, bool addEvenIfAutoDisabled) { int key = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type); if (key >= 0) { MetaType metaType = (MetaType)this.types[key]; if (metaType.Pending) { this.WaitOnLock(metaType); } return(key); } bool shouldAdd = this.AutoAddMissingTypes || addEvenIfAutoDisabled; if (Helpers.IsEnum(type) || this.TryGetBasicTypeSerializer(type) == null) { Type underlyingType = TypeModel.ResolveProxies(type); if (underlyingType != null) { key = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, underlyingType); type = underlyingType; } if (key < 0) { int opaqueToken = 0; try { this.TakeLock(ref opaqueToken); MetaType metaType; if ((metaType = this.RecogniseCommonTypes(type)) == null) { MetaType.AttributeFamily family = MetaType.GetContractFamily(this, type, null); if (family == MetaType.AttributeFamily.AutoTuple) { addEvenIfAutoDisabled = (shouldAdd = true); } if (!shouldAdd || (!Helpers.IsEnum(type) && addWithContractOnly && family == MetaType.AttributeFamily.None)) { if (demand) { TypeModel.ThrowUnexpectedType(type); } return(key); } metaType = this.Create(type); } metaType.Pending = true; bool weAdded = false; int winner = this.types.IndexOf(RuntimeTypeModel.MetaTypeFinder, type); if (winner < 0) { this.ThrowIfFrozen(); key = this.types.Add(metaType); weAdded = true; } else { key = winner; } if (weAdded) { metaType.ApplyDefaultBehaviour(); metaType.Pending = false; } } finally { this.ReleaseLock(opaqueToken); } return(key); } return(key); } if (shouldAdd && !addWithContractOnly) { throw MetaType.InbuiltType(type); } return(-1); }