2
// IfSwitchStatement.cs
5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.Collections.Generic;
29
using MonoDevelop.Core;
30
namespace MonoDevelop.DocFood
32
public class SwitchStatement : Node
34
public const string XmlTag = "Switch";
36
public List<Node> CaseSections {
41
public SwitchStatement ()
43
CaseSections = new List<Node> ();
46
public override void Run (DocGenerator generator)
48
if (!generator.EvaluateCondition (Attributes))
50
foreach (var caseSection in CaseSections) {
51
if (generator.EvaluateCondition (caseSection.Attributes)) {
52
caseSection.Children.ForEach (child => child.Run (generator));
56
Children.ForEach (child => child.Run (generator));
59
public override void Write (XmlWriter writer)
61
writer.WriteStartElement (XmlTag);
62
foreach (var pair in Attributes) {
63
writer.WriteAttributeString (pair.Key, pair.Value);
65
WriteNodeList (writer, CaseSections);
66
if (Children.Count > 0) {
67
writer.WriteStartElement ("Default");
68
WriteNodeList (writer, Children);
69
writer.WriteEndElement ();
71
writer.WriteEndElement ();
74
public static SwitchStatement Read (XmlReader reader)
76
SwitchStatement result = new SwitchStatement ();
77
if (reader.MoveToFirstAttribute ()) {
79
result.SetAttribute (reader.LocalName, reader.Value);
80
} while (reader.MoveToNextAttribute ());
82
XmlReadHelper.ReadList (reader, XmlTag, delegate () {
83
switch (reader.LocalName) {
85
result.CaseSections.Add (CaseStatement.Read (reader));
88
result.Children = Node.ReadNodeList (reader, "Default");
97
public class CaseStatement : Node
99
public const string XmlTag = "Case";
101
public override void Run (DocGenerator generator)
103
if (generator.EvaluateCondition (Attributes))
104
Children.ForEach (child => child.Run (generator));
107
public override void Write (XmlWriter writer)
109
writer.WriteStartElement (XmlTag);
110
foreach (var pair in Attributes) {
111
writer.WriteAttributeString (pair.Key, pair.Value);
113
WriteNodeList (writer, Children);
114
writer.WriteEndElement ();
117
public static CaseStatement Read (XmlReader reader)
119
CaseStatement result = new CaseStatement ();
120
if (reader.MoveToFirstAttribute ()) {
122
result.SetAttribute (reader.LocalName, reader.Value);
123
} while (reader.MoveToNextAttribute ());
125
result.Children = Node.ReadNodeList (reader, XmlTag);