public object LoadValue(XmlReaderContext context) { var type = DecodeTypeName(context.LoadFromAttribute("Type")); var etype = type.GetElementType(); var sranks = context.LoadFromAttribute("Array").Split(';'); var lengths = new int[sranks.Length]; bool empty = true; for (int i = 0; i < lengths.Length; ++i) { lengths[i] = int.Parse(sranks[i], System.Globalization.NumberStyles.None); if (lengths[i] > 0) { empty = false; } } Array res; if (lengths.Length == 1) { res = Array.CreateInstance(etype, lengths[0]); } else { res = Array.CreateInstance(etype, lengths); } if (empty) { return(res); } var values = new int[lengths.Length]; bool inc = true; context.Push(); try { if (!empty) { while (inc) { var p = ParameterPersister.Load(context); res.SetValue(p.Value, values); inc = Increment(values, lengths); if (inc) { context.Next(); } } } } finally { context.Pop(); } return(res); }
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(); } }
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(); }
public static Section Load(XmlReaderContext context) { var name = context.CurrentName; var res = new Section(name); bool empty = context.Node.ChildNodes.Count == 0; if (empty) { return(res); } var style = context.LoadFromAttribute("Style"); bool noSections = style == "NoSections"; bool noParameters = !noSections && style == "NoParameters"; if (noParameters || context.TryPush("Sections")) { try { foreach (XmlNode subsectionNode in context.Node.ChildNodes) { context.Push(subsectionNode.Name); try { res.AddSection(SectionPersister.Load(context)); } finally { context.Pop(); } } } finally { if (!noParameters) { context.Pop(); } } } if (noSections || context.TryPush("Parameters")) { try { foreach (XmlNode parameterNode in context.Node.ChildNodes) { context.Push(parameterNode.Name); try { res.AddParameter(ParameterPersister.Load(context)); } catch (Exception exc) { if (exc.IsCritical()) { throw; } } finally { context.Pop(); } } } finally { if (!noSections) { context.Pop(); } } } return(res); }