/// <summary> /// Adds a known sub-type to the inheritance model /// </summary> public MetaType AddSubType(int fieldNumber, Type derivedType) { if (!(type.IsClass || type.IsInterface) || type.IsSealed) { throw new InvalidOperationException("Sub-types can only be added to non-sealed classes"); } if (typeof(IEnumerable).IsAssignableFrom(type)) { throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed"); } ThrowIfFrozen(); MetaType derivedMeta = model[derivedType]; derivedMeta.ThrowIfFrozen(); SubType subType = new SubType(fieldNumber, derivedMeta); ThrowIfFrozen(); derivedMeta.SetBaseType(this); // includes ThrowIfFrozen if (subTypes == null) { subTypes = new BasicList(); } subTypes.Add(subType); return(this); }
/// <summary> /// Adds a known sub-type to the inheritance model /// </summary> public MetaType AddSubType(int fieldNumber, Type derivedType) { if (derivedType == null) throw new ArgumentNullException("derivedType"); if (fieldNumber < 1) throw new ArgumentOutOfRangeException("fieldNumber"); if (!(type.IsClass || type.IsInterface) || type.IsSealed) { throw new InvalidOperationException("Sub-types can only be added to non-sealed classes"); } if (typeof(IEnumerable).IsAssignableFrom(type)) { throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be subclassed"); } if (typeof(IEnumerable).IsAssignableFrom(derivedType)) { throw new ArgumentException("Repeated data (a list, collection, etc) has inbuilt behaviour and cannot be used as a subclass"); } ThrowIfFrozen(); MetaType derivedMeta = model[derivedType]; derivedMeta.ThrowIfFrozen(); SubType subType = new SubType(fieldNumber, derivedMeta); ThrowIfFrozen(); derivedMeta.SetBaseType(this); // includes ThrowIfFrozen if (subTypes == null) subTypes = new BasicList(); subTypes.Add(subType); return this; }
/// <summary> /// Obtains the subtypes that are defined for the current type /// </summary> public SubType[] GetSubtypes() { if (!HasSubtypes) { return(null); } SubType[] arr = new SubType[subTypes.Count]; subTypes.CopyTo(arr, 0); return(arr); }
/// <summary> /// Adds a known sub-type to the inheritance model /// </summary> public MetaType AddSubType(int fieldNumber, Type derivedType) { if (!type.IsClass || type.IsSealed) { throw new InvalidOperationException("Sub-types can only be adedd to non-sealed classes"); } MetaType derivedMeta = model[derivedType]; SubType subType = new SubType(fieldNumber, derivedMeta); ThrowIfFrozen(); derivedMeta.SetBaseType(this); // includes ThrowIfFrozen if (subTypes == null) subTypes = new BasicList(); subTypes.Add(subType); return this; }
/// <summary> /// Adds a known sub-type to the inheritance model /// </summary> public MetaType AddSubType(int fieldNumber, Type derivedType) { if (!type.IsClass || type.IsSealed) { throw new InvalidOperationException("Sub-types can only be adedd to non-sealed classes"); } MetaType derivedMeta = model[derivedType]; SubType subType = new SubType(fieldNumber, derivedMeta); ThrowIfFrozen(); derivedMeta.SetBaseType(this); // includes ThrowIfFrozen if (subTypes == null) { subTypes = new BasicList(); } subTypes.Add(subType); return(this); }
/// <summary> /// Obtains the subtypes that are defined for the current type /// </summary> public SubType[] GetSubtypes() { if (!HasSubtypes) return null; SubType[] arr = new SubType[subTypes.Count]; subTypes.CopyTo(arr, 0); return arr; }
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); } } }