//Size IEnumerable public static int SizeIEnumerable(ref BssomSizeContext context, IEnumerable value) { if (value == null) { return(BssomBinaryPrimitives.NullSize); } IBssomFormatter <object> formatter = context.Option.FormatterResolver.GetFormatterWithVerify <object>(); long dataLen = 0; foreach (object item in value) { dataLen += formatter.Size(ref context, item); } if (value is ICollection coll) { return(BssomBinaryPrimitives.Array2TypeSize(coll.Count, dataLen)); } else { return(BssomBinaryPrimitives.Array2TypeSizeWithFixU32Count(dataLen)); } }
//Size IEnumerable<> public static int SizeGenericIEnumerable <TElement>(ref BssomSizeContext context, IEnumerable <TElement> value) { if (value == null) { return(BssomBinaryPrimitives.NullSize); } IBssomFormatter <TElement> formatter = context.Option.FormatterResolver.GetFormatterWithVerify <TElement>(); long dataLen = 0; foreach (TElement item in value) { dataLen += formatter.Size(ref context, item); } if (value.TryGetICollectionCount(out int count)) { return(BssomBinaryPrimitives.Array2TypeSize(count, dataLen)); } else { return(BssomBinaryPrimitives.Array2TypeSizeWithFixU32Count(dataLen)); } }