예제 #1
0
 public NamespaceModel(IProject parentProject, NamespaceModel parent, string name)
 {
     this.parentProject = parentProject;
     this.parent = parent;
     this.name = name;
     this.typeDefinitions = new NullSafeSimpleModelCollection<ITypeDefinitionModel>();
     this.childNamespaces = new NullSafeSimpleModelCollection<NamespaceModel>();
 }
예제 #2
0
 public NamespaceModel(IProject parentProject, NamespaceModel parent, string name)
 {
     this.parentProject   = parentProject;
     this.parent          = parent;
     this.name            = name;
     this.typeDefinitions = new NullSafeSimpleModelCollection <ITypeDefinitionModel>();
     this.childNamespaces = new NullSafeSimpleModelCollection <NamespaceModel>();
 }
예제 #3
0
		public AssemblyModel(IEntityModelContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			this.rootNamespace = new NamespaceModel(context.Project, null, "");
			this.typeDeclarations = new TopLevelTypeDefinitionModelCollection(context);
			this.typeDeclarations.CollectionChanged += TypeDeclarationsCollectionChanged;
			this.namespaces = new KeyedModelCollection<string, NamespaceModel>(value => value.FullName);
			this.referencesModel = new AssemblyReferencesModel(this);
		}
예제 #4
0
 public AssemblyModel(IEntityModelContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     this.context          = context;
     this.rootNamespace    = new NamespaceModel(context.Project, null, "");
     this.typeDeclarations = new TopLevelTypeDefinitionModelCollection(context);
     this.typeDeclarations.CollectionChanged += TypeDeclarationsCollectionChanged;
     this.namespaces      = new KeyedModelCollection <string, NamespaceModel>(value => value.FullName);
     this.referencesModel = new AssemblyReferencesModel(this);
 }
예제 #5
0
        void TypeDeclarationsCollectionChanged(IReadOnlyCollection <ITypeDefinitionModel> removedItems, IReadOnlyCollection <ITypeDefinitionModel> addedItems)
        {
            List <IDisposable> batchList = new List <IDisposable>();

            try {
                NamespaceModel ns;
                foreach (ITypeDefinitionModel addedItem in addedItems)
                {
                    if (!namespaces.TryGetValue(addedItem.Namespace, out ns))
                    {
                        string[] parts = addedItem.Namespace.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                        int      level = 0;
                        ns = rootNamespace;
                        while (level < parts.Length)
                        {
                            var nextNS = ns.ChildNamespaces
                                         .FirstOrDefault(n => n.Name == parts[level]);
                            if (nextNS == null)
                            {
                                break;
                            }
                            ns = nextNS;
                            level++;
                        }
                        while (level < parts.Length)
                        {
                            var child = new NamespaceModel(context.Project, ns, parts[level]);
                            batchList.AddIfNotNull(ns.ChildNamespaces.BatchUpdate());
                            ns.ChildNamespaces.Add(child);
                            ns = child;
                            level++;
                        }
                        if (!namespaces.Contains(ns))
                        {
                            batchList.AddIfNotNull(namespaces.BatchUpdate());
                            namespaces.Add(ns);
                        }
                    }
                    batchList.AddIfNotNull(ns.Types.BatchUpdate());
                    ns.Types.Add(addedItem);
                }
                foreach (ITypeDefinitionModel removedItem in removedItems)
                {
                    if (namespaces.TryGetValue(removedItem.Namespace, out ns))
                    {
                        batchList.AddIfNotNull(ns.Types.BatchUpdate());
                        ns.Types.Remove(removedItem);
                        if (ns.Types.Count == 0)
                        {
                            batchList.AddIfNotNull(namespaces.BatchUpdate());
                            namespaces.Remove(ns);
                        }
                        while (ns.ParentNamespace != null)
                        {
                            var p = ((NamespaceModel)ns.ParentNamespace);
                            if (ns.ChildNamespaces.Count == 0 && ns.Types.Count == 0)
                            {
                                batchList.AddIfNotNull(p.ChildNamespaces.BatchUpdate());
                                p.ChildNamespaces.Remove(ns);
                            }
                            ns = p;
                        }
                    }
                }
            } finally {
                batchList.Reverse();
                foreach (IDisposable d in batchList)
                {
                    d.Dispose();
                }
            }
        }
예제 #6
0
		void TypeDeclarationsCollectionChanged(IReadOnlyCollection<ITypeDefinitionModel> removedItems, IReadOnlyCollection<ITypeDefinitionModel> addedItems)
		{
			List<IDisposable> batchList = new List<IDisposable>();
			try {
				NamespaceModel ns;
				foreach (ITypeDefinitionModel addedItem in addedItems) {
					if (!namespaces.TryGetValue(addedItem.Namespace, out ns)) {
						string[] parts = addedItem.Namespace.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
						int level = 0;
						ns = rootNamespace;
						while (level < parts.Length) {
							var nextNS = ns.ChildNamespaces
								.FirstOrDefault(n => n.Name == parts[level]);
							if (nextNS == null) break;
							ns = nextNS;
							level++;
						}
						while (level < parts.Length) {
							var child = new NamespaceModel(context.Project, ns, parts[level]);
							batchList.AddIfNotNull(ns.ChildNamespaces.BatchUpdate());
							ns.ChildNamespaces.Add(child);
							ns = child;
							level++;
						}
						if (!namespaces.Contains(ns)) {
							batchList.AddIfNotNull(namespaces.BatchUpdate());
							namespaces.Add(ns);
						}
					}
					batchList.AddIfNotNull(ns.Types.BatchUpdate());
					ns.Types.Add(addedItem);
				}
				foreach (ITypeDefinitionModel removedItem in removedItems) {
					if (namespaces.TryGetValue(removedItem.Namespace, out ns)) {
						batchList.AddIfNotNull(ns.Types.BatchUpdate());
						ns.Types.Remove(removedItem);
						if (ns.Types.Count == 0) {
							batchList.AddIfNotNull(namespaces.BatchUpdate());
							namespaces.Remove(ns);
						}
						while (ns.ParentNamespace != null) {
							var p = ((NamespaceModel)ns.ParentNamespace);
							if (ns.ChildNamespaces.Count == 0 && ns.Types.Count == 0) {
								batchList.AddIfNotNull(p.ChildNamespaces.BatchUpdate());
								p.ChildNamespaces.Remove(ns);
							}
							ns = p;
						}
					}
				}
			} finally {
				batchList.Reverse();
				foreach (IDisposable d in batchList)
					d.Dispose();
			}
		}