private void CascadeDependents(BasicList list, MetaType metaType) { MetaType surrogateOrBaseOrSelf; if (metaType.IsList) { Type listItemType = TypeModel.GetListItemType(this, metaType.Type); if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out WireType _, asReference: false, dynamicType: false, overwriteList: false, allowComplexTypes: false) != null) { return; } int num = FindOrAddAuto(listItemType, demand: false, addWithContractOnly: false, addEvenIfAutoDisabled: false); if (num >= 0) { surrogateOrBaseOrSelf = ((MetaType)types[num]).GetSurrogateOrBaseOrSelf(deep: false); if (!list.Contains(surrogateOrBaseOrSelf)) { list.Add(surrogateOrBaseOrSelf); CascadeDependents(list, surrogateOrBaseOrSelf); } } return; } if (metaType.IsAutoTuple) { if (MetaType.ResolveTupleConstructor(metaType.Type, out MemberInfo[] mappedMembers) != null)
private void CascadeDependents(BasicList list, MetaType metaType) { if (metaType.IsList) { Type listItemType = TypeModel.GetListItemType(this, metaType.Type); if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out WireType _, false, false, false, false) == null) { int num = FindOrAddAuto(listItemType, false, false, false); if (num >= 0) { MetaType surrogateOrBaseOrSelf = ((MetaType)types[num]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(surrogateOrBaseOrSelf)) { list.Add(surrogateOrBaseOrSelf); CascadeDependents(list, surrogateOrBaseOrSelf); } } } } else { MetaType surrogateOrBaseOrSelf; if (metaType.IsAutoTuple) { if (MetaType.ResolveTupleConstructor(metaType.Type, out MemberInfo[] array) != (ConstructorInfo)null)
private static void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType) { if (type == null) { return; } // handle arrays if (type.IsArray) { if (type.GetArrayRank() != 1) { throw new NotSupportedException("Multi-dimension arrays are supported"); } itemType = type.GetElementType(); if (itemType == typeof(byte)) { defaultType = itemType = null; } else { defaultType = Helpers.MakeArrayType(type); } } // handle lists if (itemType == null) { itemType = TypeModel.GetListItemType(type); } // check for nested data (not allowed) if (itemType != null) { Type nestedItemType = null, nestedDefaultType = null; ResolveListTypes(itemType, ref nestedItemType, ref nestedDefaultType); if (nestedItemType != null) { throw new NotSupportedException("Nested or jagged lists and arrays are not supported"); } } if (itemType != null && defaultType == null) { if (type.IsClass && !type.IsAbstract && type.GetConstructor(Helpers.EmptyTypes) != null) { defaultType = type; } if (defaultType == null) { if (type.IsInterface) { Type[] genArgs; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IDictionary <,>) && itemType == typeof(System.Collections.Generic.KeyValuePair <,>).MakeGenericType(genArgs = type.GetGenericArguments())) { defaultType = typeof(System.Collections.Generic.Dictionary <,>).MakeGenericType(genArgs); } else { defaultType = typeof(System.Collections.Generic.List <>).MakeGenericType(itemType); } } } // verify that the default type is appropriate if (defaultType != null && !type.IsAssignableFrom(defaultType)) { defaultType = null; } } }
// Token: 0x06000388 RID: 904 RVA: 0x000132C0 File Offset: 0x000114C0 internal void ResolveListTypes(Type type, ref Type itemType, ref Type defaultType) { if (type == null) { return; } if (Helpers.GetTypeCode(type) != ProtoTypeCode.Unknown) { return; } if (this[type].IgnoreListHandling) { return; } if (type.IsArray) { if (type.GetArrayRank() != 1) { throw new NotSupportedException("Multi-dimension arrays are supported"); } itemType = type.GetElementType(); if (itemType == base.MapType(typeof(byte))) { Type type2; itemType = (type2 = null); defaultType = type2; } else { defaultType = type; } } if (itemType == null) { itemType = TypeModel.GetListItemType(this, type); } if (itemType != null) { Type type3 = null; Type type4 = null; this.ResolveListTypes(itemType, ref type3, ref type4); if (type3 != null) { throw TypeModel.CreateNestedListsNotSupported(); } } if (itemType != null && defaultType == null) { if (type.IsClass && !type.IsAbstract && Helpers.GetConstructor(type, Helpers.EmptyTypes, true) != null) { defaultType = type; } if (defaultType == null && type.IsInterface) { Type[] genericArguments; if (type.IsGenericType && type.GetGenericTypeDefinition() == base.MapType(typeof(IDictionary <, >)) && itemType == base.MapType(typeof(KeyValuePair <, >)).MakeGenericType(genericArguments = type.GetGenericArguments())) { defaultType = base.MapType(typeof(Dictionary <, >)).MakeGenericType(genericArguments); } else { defaultType = base.MapType(typeof(List <>)).MakeGenericType(new Type[] { itemType }); } } if (defaultType != null && !Helpers.IsAssignableFrom(type, defaultType)) { defaultType = null; } } }
// Token: 0x06000375 RID: 885 RVA: 0x00012FA4 File Offset: 0x000111A4 public MetaType Add(Type type, bool applyDefaultBehaviour) { if (type == null) { throw new ArgumentNullException("type"); } MetaType metaType = this.FindWithoutAdd(type); if (metaType != null) { return(metaType); } int opaqueToken = 0; if (type.IsInterface && base.MapType(MetaType.ienumerable).IsAssignableFrom(type) && TypeModel.GetListItemType(this, type) == null) { throw new ArgumentException("IEnumerable[<T>] data cannot be used as a meta-type unless an Add method can be resolved"); } try { metaType = this.RecogniseCommonTypes(type); if (metaType != null) { if (!applyDefaultBehaviour) { throw new ArgumentException("Default behaviour must be observed for certain types with special handling; " + type.FullName, "applyDefaultBehaviour"); } applyDefaultBehaviour = false; } if (metaType == null) { metaType = this.Create(type); } metaType.Pending = true; this.TakeLock(ref opaqueToken); if (this.FindWithoutAdd(type) != null) { throw new ArgumentException("Duplicate type", "type"); } this.ThrowIfFrozen(); this.types.Add(metaType); if (applyDefaultBehaviour) { metaType.ApplyDefaultBehaviour(); } metaType.Pending = false; } finally { this.ReleaseLock(opaqueToken); } return(metaType); }
// Token: 0x0600036A RID: 874 RVA: 0x00012A1C File Offset: 0x00010C1C private void CascadeDependents(BasicList list, MetaType metaType) { if (metaType.IsList) { Type listItemType = TypeModel.GetListItemType(this, metaType.Type); WireType wireType; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out wireType, false, false, false, false) == null) { int num = this.FindOrAddAuto(listItemType, false, false, false); if (num >= 0) { MetaType metaType2 = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); return; } } } } else { MetaType metaType2; if (metaType.IsAutoTuple) { MemberInfo[] array; if (MetaType.ResolveTupleConstructor(metaType.Type, out array) != null) { for (int i = 0; i < array.Length; i++) { Type type = null; if (array[i] is PropertyInfo) { type = ((PropertyInfo)array[i]).PropertyType; } else if (array[i] is FieldInfo) { type = ((FieldInfo)array[i]).FieldType; } WireType wireType2; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType2, false, false, false, false) == null) { int num2 = this.FindOrAddAuto(type, false, false, false); if (num2 >= 0) { metaType2 = ((MetaType)this.types[num2]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } } } } else { foreach (object obj in metaType.Fields) { ValueMember valueMember = (ValueMember)obj; Type type2 = valueMember.ItemType; if (type2 == null) { type2 = valueMember.MemberType; } WireType wireType3; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out wireType3, false, false, false, false) == null) { int num3 = this.FindOrAddAuto(type2, false, false, false); if (num3 >= 0) { metaType2 = ((MetaType)this.types[num3]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } } } if (metaType.HasSubtypes) { SubType[] subtypes = metaType.GetSubtypes(); for (int j = 0; j < subtypes.Length; j++) { metaType2 = subtypes[j].DerivedType.GetSurrogateOrSelf(); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } metaType2 = metaType.BaseType; if (metaType2 != null) { metaType2 = metaType2.GetSurrogateOrSelf(); } if (metaType2 != null && !list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } }
private IProtoTypeSerializer BuildSerializer() { if (surrogate != null) { MetaType mt = model[surrogate], mtBase; while ((mtBase = mt.baseType) != null) { mt = mtBase; } return(new SurrogateSerializer(type, surrogate, mt.Serializer)); } Type itemType = TypeModel.GetListItemType(type); if (itemType != null) { ValueMember fakeMember = new ValueMember(model, 1, type, itemType, type, DataFormat.Default); return(new TypeSerializer(type, new int[] { 1 }, new IProtoSerializer[] { fakeMember.Serializer }, null, true, true, null, constructType)); } fields.Trim(); int fieldCount = fields.Count; int subTypeCount = subTypes == null ? 0 : subTypes.Count; int[] fieldNumbers = new int[fieldCount + subTypeCount]; IProtoSerializer[] serializers = new IProtoSerializer[fieldCount + subTypeCount]; int i = 0; if (subTypeCount != 0) { foreach (SubType subType in subTypes) { fieldNumbers[i] = subType.FieldNumber; serializers[i++] = subType.Serializer; } } if (fieldCount != 0) { foreach (ValueMember member in fields) { fieldNumbers[i] = member.FieldNumber; serializers[i++] = member.Serializer; } } BasicList baseCtorCallbacks = null; MetaType tmp = BaseType; while (tmp != null) { MethodInfo method = tmp.HasCallbacks ? tmp.Callbacks.BeforeDeserialize : null; if (method != null) { if (baseCtorCallbacks == null) { baseCtorCallbacks = new BasicList(); } baseCtorCallbacks.Add(method); } tmp = tmp.BaseType; } MethodInfo[] arr = null; if (baseCtorCallbacks != null) { arr = new MethodInfo[baseCtorCallbacks.Count]; baseCtorCallbacks.CopyTo(arr, 0); Array.Reverse(arr); } return(new TypeSerializer(type, fieldNumbers, serializers, arr, baseType == null, UseConstructor, callbacks, constructType)); }
private void CascadeDependents(BasicList list, MetaType metaType) { if (metaType.IsList) { Type listItemType = TypeModel.GetListItemType(this, metaType.Type); WireType wireType; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, listItemType, out wireType, false, false, false, false) == null) { int num = this.FindOrAddAuto(listItemType, false, false, false); if (num >= 0) { MetaType metaType2 = ((MetaType)this.types[num]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } } else { MetaType metaType2; if (metaType.IsAutoTuple) { MemberInfo[] array; if (MetaType.ResolveTupleConstructor(metaType.Type, out array) != null) { for (int i = 0; i < array.Length; i++) { Type type = null; if (array[i] is PropertyInfo) { type = ((PropertyInfo)array[i]).get_PropertyType(); } else if (array[i] is FieldInfo) { type = ((FieldInfo)array[i]).get_FieldType(); } WireType wireType2; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out wireType2, false, false, false, false) == null) { int num2 = this.FindOrAddAuto(type, false, false, false); if (num2 >= 0) { metaType2 = ((MetaType)this.types[num2]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } } } } else { IEnumerator enumerator = metaType.Fields.GetEnumerator(); try { while (enumerator.MoveNext()) { ValueMember valueMember = (ValueMember)enumerator.get_Current(); Type type2 = valueMember.ItemType; if (type2 == null) { type2 = valueMember.MemberType; } WireType wireType3; if (ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type2, out wireType3, false, false, false, false) == null) { int num3 = this.FindOrAddAuto(type2, false, false, false); if (num3 >= 0) { metaType2 = ((MetaType)this.types[num3]).GetSurrogateOrBaseOrSelf(false); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } if (metaType.HasSubtypes) { SubType[] subtypes = metaType.GetSubtypes(); for (int j = 0; j < subtypes.Length; j++) { SubType subType = subtypes[j]; metaType2 = subType.DerivedType.GetSurrogateOrSelf(); if (!list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } } metaType2 = metaType.BaseType; if (metaType2 != null) { metaType2 = metaType2.GetSurrogateOrSelf(); } if (metaType2 != null && !list.Contains(metaType2)) { list.Add(metaType2); this.CascadeDependents(list, metaType2); } } }