~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins.Description/ObjectDescriptionCollection.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ObjectDescriptionCollection.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.Xml;
 
32
using System.Collections;
 
33
using System.Collections.Specialized;
 
34
 
 
35
namespace Mono.Addins.Description
 
36
{
 
37
        /// <summary>
 
38
        /// Base class for add-in description collections.
 
39
        /// </summary>
 
40
        public class ObjectDescriptionCollection: CollectionBase
 
41
        {
 
42
                object owner;
 
43
                
 
44
                internal ObjectDescriptionCollection (object owner)
 
45
                {
 
46
                        this.owner = owner;
 
47
                }
 
48
                
 
49
                /// <summary>
 
50
                /// Initializes a new instance of the <see cref="Mono.Addins.Description.ObjectDescriptionCollection"/> class.
 
51
                /// </summary>
 
52
                public ObjectDescriptionCollection ()
 
53
                {
 
54
                }
 
55
                
 
56
                /// <summary>
 
57
                /// Add an object.
 
58
                /// </summary>
 
59
                /// <param name='ep'>
 
60
                /// The object.
 
61
                /// </param>
 
62
                public void Add (ObjectDescription ep)
 
63
                {
 
64
                        List.Add (ep);
 
65
                }
 
66
                
 
67
                /// <summary>
 
68
                /// Adds a collection of objects.
 
69
                /// </summary>
 
70
                /// <param name='collection'>
 
71
                /// The objects to add.
 
72
                /// </param>
 
73
                public void AddRange (ObjectDescriptionCollection collection)
 
74
                {
 
75
                        foreach (ObjectDescription ob in collection)
 
76
                                Add (ob);
 
77
                }
 
78
                
 
79
                /// <summary>
 
80
                /// Insert an object.
 
81
                /// </summary>
 
82
                /// <param name='index'>
 
83
                /// Insertion index.
 
84
                /// </param>
 
85
                /// <param name='ep'>
 
86
                /// The object.
 
87
                /// </param>
 
88
                public void Insert (int index, ObjectDescription ep)
 
89
                {
 
90
                        List.Insert (index, ep);
 
91
                }
 
92
                
 
93
                /// <summary>
 
94
                /// Removes an object.
 
95
                /// </summary>
 
96
                /// <param name='ep'>
 
97
                /// Object to remove.
 
98
                /// </param>
 
99
                public void Remove (ObjectDescription ep)
 
100
                {
 
101
                        List.Remove (ep);
 
102
                }
 
103
                
 
104
                /// <summary>
 
105
                /// Checks if an object is present in the collection.
 
106
                /// </summary>
 
107
                /// <param name='ob'>
 
108
                /// Objecect to check.
 
109
                /// </param>
 
110
                public bool Contains (ObjectDescription ob)
 
111
                {
 
112
                        return List.Contains (ob);
 
113
                }
 
114
                
 
115
#pragma warning disable 1591
 
116
                protected override void OnRemove (int index, object value)
 
117
                {
 
118
                        ObjectDescription ep = (ObjectDescription) value;
 
119
                        if (ep.Element != null) {
 
120
                                ep.Element.ParentNode.RemoveChild (ep.Element);
 
121
                                ep.Element = null;
 
122
                        }
 
123
                        if (owner != null)
 
124
                                ep.SetParent (null);
 
125
                }
 
126
                
 
127
                protected override void OnInsertComplete (int index, object value)
 
128
                {
 
129
                        if (owner != null)
 
130
                                ((ObjectDescription)value).SetParent (owner);
 
131
                }
 
132
 
 
133
                protected override void OnSetComplete (int index, object oldValue, object newValue)
 
134
                {
 
135
                        if (owner != null) {
 
136
                                ((ObjectDescription)newValue).SetParent (owner);
 
137
                                ((ObjectDescription)oldValue).SetParent (null);
 
138
                        }
 
139
                }
 
140
 
 
141
                protected override void OnClear ()
 
142
                {
 
143
                        if (owner != null) {
 
144
                                foreach (ObjectDescription ob in List)
 
145
                                        ob.SetParent (null);
 
146
                        }
 
147
                }
 
148
#pragma warning restore 1591
 
149
 
 
150
                
 
151
                internal void SaveXml (XmlElement parent)
 
152
                {
 
153
                        foreach (ObjectDescription ob in this)
 
154
                                ob.SaveXml (parent);
 
155
                }
 
156
                
 
157
                internal void Verify (string location, StringCollection errors)
 
158
                {
 
159
                        int n=0;
 
160
                        foreach (ObjectDescription ob in this) {
 
161
                                ob.Verify (location + "[" + n + "]/", errors);
 
162
                                n++;
 
163
                        }
 
164
                }
 
165
        }
 
166
}