예제 #1
0
        //Helper function used by other components if need to update import context item
        public static void AddImport(string importedNamespace, EditingContext editingContext)
        {
            //For types defined without any namespace, Type.Namespace is null instead of empty. We don't need to add any namespace to Import list in this case
            if (string.IsNullOrEmpty(importedNamespace))
            {
                return;
            }

            Fx.Assert(editingContext != null, "EditingContext shouldn't be null.");
            ModelService modelService = editingContext.Services.GetService <ModelService>();

            Fx.Assert(modelService != null, "EditingContext should contains ModelService.");
            ModelItemCollection importsCollection = modelService.Root.Properties[NamespaceListPropertyDescriptor.ImportCollectionPropertyName].Collection;
            NamespaceList       namespaceList     = importsCollection.GetCurrentValue() as NamespaceList;

            if (namespaceList.Lookup(importedNamespace) == -1)
            {
                importsCollection.Add(new NamespaceData {
                    Namespace = importedNamespace
                });
            }
            else
            {
                namespaceList.UpdateAssemblyInfo(importedNamespace);
            }
        }