2424// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525// THE SOFTWARE.
2626using System ;
27- using System . Collections . Concurrent ;
2827using System . Collections . Generic ;
29- using System . Xml . Linq ;
28+ using System . Linq ;
3029using MonoDevelop . Core ;
3130
3231namespace MonoDevelop . Projects . MSBuild
3332{
3433 class MSBuildPropertyGroupEvaluated : MSBuildNode , IMSBuildPropertyGroupEvaluated , IMSBuildProjectObject
3534 {
36- protected ConcurrentDictionary < string , IMSBuildPropertyEvaluated > properties = new ConcurrentDictionary < string , IMSBuildPropertyEvaluated > ( StringComparer . OrdinalIgnoreCase ) ;
35+ protected Dictionary < string , IMSBuildPropertyEvaluated > properties = new Dictionary < string , IMSBuildPropertyEvaluated > ( StringComparer . OrdinalIgnoreCase ) ;
3736 MSBuildEngine engine ;
3837
3938 internal MSBuildPropertyGroupEvaluated ( MSBuildProject parent )
@@ -43,45 +42,60 @@ internal MSBuildPropertyGroupEvaluated (MSBuildProject parent)
4342
4443 internal void Sync ( MSBuildEngine engine , object item , bool clearProperties = true )
4544 {
46- if ( clearProperties )
47- properties . Clear ( ) ;
45+ if ( clearProperties ) {
46+ lock ( properties ) {
47+ properties . Clear ( ) ;
48+ }
49+ }
4850 this . engine = engine ;
4951 foreach ( var propName in engine . GetItemMetadataNames ( item ) ) {
5052 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+ }
5256 }
5357 }
5458
5559 public bool HasProperty ( string name )
5660 {
57- return properties . ContainsKey ( name ) ;
61+ lock ( properties ) {
62+ return properties . ContainsKey ( name ) ;
63+ }
5864 }
5965
6066 public IMSBuildPropertyEvaluated GetProperty ( string name )
6167 {
6268 IMSBuildPropertyEvaluated prop ;
63- properties . TryGetValue ( name , out prop ) ;
69+ lock ( properties ) {
70+ properties . TryGetValue ( name , out prop ) ;
71+ }
6472 return prop ;
6573 }
6674
6775 internal void SetProperty ( string key , IMSBuildPropertyEvaluated value )
6876 {
69- properties [ key ] = value ;
77+ lock ( properties ) {
78+ properties [ key ] = value ;
79+ }
7080 }
7181
7282 internal void SetProperties ( Dictionary < string , IMSBuildPropertyEvaluated > properties )
7383 {
74- this . properties = new ConcurrentDictionary < string , IMSBuildPropertyEvaluated > ( properties , StringComparer . OrdinalIgnoreCase ) ;
84+ this . properties = properties ;
7585 }
7686
7787 public IEnumerable < IMSBuildPropertyEvaluated > GetProperties ( )
7888 {
79- return properties . Values ;
89+ lock ( properties ) {
90+ return properties . Values . ToArray ( ) ;
91+ }
8092 }
8193
8294 internal bool RemoveProperty ( string name )
8395 {
84- return properties . TryRemove ( name , out _ ) ;
96+ lock ( properties ) {
97+ return properties . Remove ( name ) ;
98+ }
8599 }
86100
87101 public string GetValue ( string name , string defaultValue = null )
@@ -153,11 +167,15 @@ public MSBuildEvaluatedPropertyCollection (MSBuildProject parent): base (parent)
153167
154168 internal void SyncCollection ( MSBuildEngine e , object project )
155169 {
156- properties . Clear ( ) ;
170+ lock ( properties ) {
171+ properties . Clear ( ) ;
172+ }
157173 foreach ( var p in e . GetEvaluatedProperties ( project ) ) {
158174 string name , value , finalValue ; bool definedMultipleTimes ;
159175 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+ }
161179 }
162180 }
163181
@@ -244,7 +262,9 @@ MSBuildPropertyEvaluated AddProperty (string name)
244262 {
245263 var p = new MSBuildPropertyEvaluated ( ParentProject , name , null , null ) ;
246264 p . IsNew = true ;
247- properties [ name ] = p ;
265+ lock ( properties ) {
266+ properties [ name ] = p ;
267+ }
248268 return p ;
249269 }
250270
@@ -281,13 +301,19 @@ void IPropertyGroupListener.PropertyRemoved (MSBuildProperty prop)
281301 // that property group property.
282302 if ( ep . IsNew || ! prop . IsNew ) {
283303 ep . IsNew = false ;
284- properties . TryRemove ( ep . Name , out _ ) ;
304+ lock ( properties ) {
305+ properties . Remove ( ep . Name ) ;
306+ }
285307 }
286308 }
287309 }
288310
289311 public IEnumerable < IMSBuildPropertyEvaluated > Properties {
290- get { return properties . Values ; }
312+ get {
313+ lock ( properties ) {
314+ return properties . Values . ToArray ( ) ;
315+ }
316+ }
291317 }
292318 }
293319
0 commit comments