[corlib] Update ValueTuple implementation
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / View / ImportedNamespaceContextItem.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Hosting
6 {
7     using System;    
8     using System.Runtime;
9     using System.Collections.ObjectModel;
10     using System.Activities.Presentation.Services;
11     using System.Activities.Presentation.Model;
12
13     
14     [Fx.Tag.XamlVisible(false)]
15     public sealed class ImportedNamespaceContextItem : ContextItem
16     {
17         bool initialized = false;
18         Collection<string> importedNamespaces;
19
20         public Collection<string> ImportedNamespaces
21         {
22             get
23             {
24                 if (this.importedNamespaces == null)
25                 {
26                     initialized = true;
27                     this.importedNamespaces = new Collection<string>();
28                 }
29                 return this.importedNamespaces;
30             }
31         }
32
33         public override Type ItemType
34         {
35             get { return typeof(ImportedNamespaceContextItem); }
36         }
37
38         public void EnsureInitialized(EditingContext context)
39         {
40             if (!initialized)
41             {
42                 ModelService modelService = context.Services.GetService<ModelService>();                
43                 Fx.Assert(modelService != null, "ModelService shouldn't be null in EditingContext.");
44                 Fx.Assert(modelService.Root != null, "model must have a root");
45                 ModelItemCollection importsModelItem = modelService.Root.Properties[NamespaceListPropertyDescriptor.ImportCollectionPropertyName].Collection;
46                 Fx.Assert(importsModelItem != null, "root must have imports");                
47                 foreach (ModelItem import in importsModelItem)
48                 {
49                     this.ImportedNamespaces.Add(import.Properties[NamespaceListPropertyDescriptor.NamespacePropertyName].ComputedValue as string);
50                 }
51             }
52         }
53     }
54 }