コード例 #1
0
ファイル: XmlAdapter.cs プロジェクト: oqewok/gitter
            public void Store(XmlWriterContext context, Parameter parameter)
            {
                var arr  = (Array)parameter.Value;
                int rank = arr.Rank;

                int[] values  = new int[rank];
                int[] ubounds = new int[rank];
                int[] lbounds = new int[rank];
                var   sb      = new StringBuilder();
                bool  empty   = true;

                for (int i = 0; i < rank; ++i)
                {
                    lbounds[i] = values[i] = arr.GetLowerBound(i);
                    ubounds[i] = arr.GetUpperBound(i);
                    int l = ubounds[i] - lbounds[i] + 1;
                    if (l > 0)
                    {
                        empty = false;
                    }
                    sb.Append(l);
                    if (i != rank - 1)
                    {
                        sb.Append(';');
                    }
                }
                context.Push(parameter.Name);
                context.StoreInAttribute("Type", EncodeTypeName(parameter.Type));
                context.StoreInAttribute("Array", sb.ToString());
                try
                {
                    if (!empty)
                    {
                        var  etype = parameter.Type.GetElementType();
                        bool inc   = true;
                        while (inc)
                        {
                            var value = arr.GetValue(values);
                            var p     = new Parameter("Item", TypeHelpers.GetType(etype, value), value);
                            ParameterPersister.Store(context, p);
                            inc = Increment(values, lbounds, ubounds);
                        }
                    }
                }
                finally
                {
                    context.Pop();
                }
            }
コード例 #2
0
ファイル: XmlAdapter.cs プロジェクト: oqewok/gitter
            public static void Store(XmlWriterContext context, Section section)
            {
                context.Push(section.Name);
                int sections   = section.SectionCount;
                int parameters = section.ParameterCount;

                if (parameters != 0 || sections != 0)
                {
                    bool saveDirect = sections == 0 || parameters == 0;
                    if (parameters == 0)
                    {
                        context.StoreInAttribute("Style", "NoParameters");
                    }
                    else if (sections == 0)
                    {
                        context.StoreInAttribute("Style", "NoSections");
                    }
                    if (section.SectionCount != 0)
                    {
                        if (!saveDirect)
                        {
                            context.Push("Sections");
                        }
                        try
                        {
                            foreach (var subsection in section.Sections)
                            {
                                SectionPersister.Store(context, subsection);
                            }
                        }
                        finally
                        {
                            if (!saveDirect)
                            {
                                context.Pop();
                            }
                        }
                    }
                    if (section.ParameterCount != 0)
                    {
                        if (!saveDirect)
                        {
                            context.Push("Parameters");
                        }
                        try
                        {
                            foreach (var parameter in section.Parameters)
                            {
                                ParameterPersister.Store(context, parameter);
                            }
                        }
                        finally
                        {
                            if (!saveDirect)
                            {
                                context.Pop();
                            }
                        }
                    }
                }
                context.Pop();
            }