24
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
25
// THE SOFTWARE.
26
26
using System ;
27
- using System . Collections . Concurrent ;
28
27
using System . Collections . Generic ;
29
- using System . Xml . Linq ;
28
+ using System . Linq ;
30
29
using MonoDevelop . Core ;
31
30
32
31
namespace MonoDevelop . Projects . MSBuild
33
32
{
34
33
class MSBuildPropertyGroupEvaluated : MSBuildNode , IMSBuildPropertyGroupEvaluated , IMSBuildProjectObject
35
34
{
36
- protected ConcurrentDictionary < string , IMSBuildPropertyEvaluated > properties = new ConcurrentDictionary < string , IMSBuildPropertyEvaluated > ( StringComparer . OrdinalIgnoreCase ) ;
35
+ protected Dictionary < string , IMSBuildPropertyEvaluated > properties = new Dictionary < string , IMSBuildPropertyEvaluated > ( StringComparer . OrdinalIgnoreCase ) ;
37
36
MSBuildEngine engine ;
38
37
39
38
internal MSBuildPropertyGroupEvaluated ( MSBuildProject parent )
@@ -43,45 +42,60 @@ internal MSBuildPropertyGroupEvaluated (MSBuildProject parent)
43
42
44
43
internal void Sync ( MSBuildEngine engine , object item , bool clearProperties = true )
45
44
{
46
- if ( clearProperties )
47
- properties . Clear ( ) ;
45
+ if ( clearProperties ) {
46
+ lock ( properties ) {
47
+ properties . Clear ( ) ;
48
+ }
49
+ }
48
50
this . engine = engine ;
49
51
foreach ( var propName in engine . GetItemMetadataNames ( item ) ) {
50
52
var prop = new MSBuildPropertyEvaluated ( ParentProject , propName , engine . GetItemMetadata ( item , propName ) , engine . GetEvaluatedItemMetadata ( item , propName ) ) ;
51
- properties [ propName ] = prop ;
53
+ lock ( properties ) {
54
+ properties [ propName ] = prop ;
55
+ }
52
56
}
53
57
}
54
58
55
59
public bool HasProperty ( string name )
56
60
{
57
- return properties . ContainsKey ( name ) ;
61
+ lock ( properties ) {
62
+ return properties . ContainsKey ( name ) ;
63
+ }
58
64
}
59
65
60
66
public IMSBuildPropertyEvaluated GetProperty ( string name )
61
67
{
62
68
IMSBuildPropertyEvaluated prop ;
63
- properties . TryGetValue ( name , out prop ) ;
69
+ lock ( properties ) {
70
+ properties . TryGetValue ( name , out prop ) ;
71
+ }
64
72
return prop ;
65
73
}
66
74
67
75
internal void SetProperty ( string key , IMSBuildPropertyEvaluated value )
68
76
{
69
- properties [ key ] = value ;
77
+ lock ( properties ) {
78
+ properties [ key ] = value ;
79
+ }
70
80
}
71
81
72
82
internal void SetProperties ( Dictionary < string , IMSBuildPropertyEvaluated > properties )
73
83
{
74
- this . properties = new ConcurrentDictionary < string , IMSBuildPropertyEvaluated > ( properties , StringComparer . OrdinalIgnoreCase ) ;
84
+ this . properties = properties ;
75
85
}
76
86
77
87
public IEnumerable < IMSBuildPropertyEvaluated > GetProperties ( )
78
88
{
79
- return properties . Values ;
89
+ lock ( properties ) {
90
+ return properties . Values . ToArray ( ) ;
91
+ }
80
92
}
81
93
82
94
internal bool RemoveProperty ( string name )
83
95
{
84
- return properties . TryRemove ( name , out _ ) ;
96
+ lock ( properties ) {
97
+ return properties . Remove ( name ) ;
98
+ }
85
99
}
86
100
87
101
public string GetValue ( string name , string defaultValue = null )
@@ -153,11 +167,15 @@ public MSBuildEvaluatedPropertyCollection (MSBuildProject parent): base (parent)
153
167
154
168
internal void SyncCollection ( MSBuildEngine e , object project )
155
169
{
156
- properties . Clear ( ) ;
170
+ lock ( properties ) {
171
+ properties . Clear ( ) ;
172
+ }
157
173
foreach ( var p in e . GetEvaluatedProperties ( project ) ) {
158
174
string name , value , finalValue ; bool definedMultipleTimes ;
159
175
e . GetPropertyInfo ( p , out name , out value , out finalValue , out definedMultipleTimes ) ;
160
- properties [ name ] = new MSBuildPropertyEvaluated ( ParentProject , name , value , finalValue , definedMultipleTimes ) ;
176
+ lock ( properties ) {
177
+ properties [ name ] = new MSBuildPropertyEvaluated ( ParentProject , name , value , finalValue , definedMultipleTimes ) ;
178
+ }
161
179
}
162
180
}
163
181
@@ -244,7 +262,9 @@ MSBuildPropertyEvaluated AddProperty (string name)
244
262
{
245
263
var p = new MSBuildPropertyEvaluated ( ParentProject , name , null , null ) ;
246
264
p . IsNew = true ;
247
- properties [ name ] = p ;
265
+ lock ( properties ) {
266
+ properties [ name ] = p ;
267
+ }
248
268
return p ;
249
269
}
250
270
@@ -281,13 +301,19 @@ void IPropertyGroupListener.PropertyRemoved (MSBuildProperty prop)
281
301
// that property group property.
282
302
if ( ep . IsNew || ! prop . IsNew ) {
283
303
ep . IsNew = false ;
284
- properties . TryRemove ( ep . Name , out _ ) ;
304
+ lock ( properties ) {
305
+ properties . Remove ( ep . Name ) ;
306
+ }
285
307
}
286
308
}
287
309
}
288
310
289
311
public IEnumerable < IMSBuildPropertyEvaluated > Properties {
290
- get { return properties . Values ; }
312
+ get {
313
+ lock ( properties ) {
314
+ return properties . Values . ToArray ( ) ;
315
+ }
316
+ }
291
317
}
292
318
}
293
319
0 commit comments