示例#1
0
        void EmitWriteContentEnumerable(SerializerCodeGen g, Local enumerable, Operand fieldNumber, bool pack, Action first = null)
        {
            Type enumerableGenericType = g.ctx.MapType(typeof(IEnumerable <>)).MakeGenericType(_itemType);

            bool castNeeded = !Helpers.IsAssignableFrom(enumerableGenericType, enumerable.Type);

            using (var isFirst = g.ctx.Local(typeof(bool)))
            {
                g.Assign(isFirst, true);

                var el = g.ForEach(castNeeded ? g.ctx.MapType(typeof(object)) : _itemType, enumerable);
                {
                    g.If(isFirst);
                    {
                        first?.Invoke();
                    }
                    g.End();

                    EmitWriteElement(g, castNeeded ? el.Cast(_itemType) : el, fieldNumber, pack, isFirst);

                    g.Assign(isFirst, false);
                }
                g.End();
            }
        }