示例#1
0
        /// <summary>
        /// Adds a namespace to the top level namespace.
        /// </summary>
        /// <param name="Name">Required. The name of the new namespace.</param>
        /// <param name="Position">Optional. Default = 0. The code element after which to add the new element. If the value is a CodeElement, then the new element is added immediately after it.</param>
        /// <returns></returns>
        public VSCodeNamespace AddNamespace(string Name, object Position)
        {
            Initialize();

            InitTopNamespace();

            CDCodeNamespace cn = new CDCodeNamespace(Name);

            EnsureNamespaceLinked(cn);

            VSCodeNamespace after = Position as VSCodeNamespace;

            if (after != null)
            {
                for (int i = 0; i < _ccu.Namespaces.Count; i++)
                {
                    if (_ccu.Namespaces[i].UserData[CodeKey] == after)
                    {
                        _ccu.Namespaces.Insert(i + 1, cn);
                    }
                }
            }
            else
            {
                int index = (int)Position - 1;
                _ccu.Namespaces.Insert(index, cn);
            }


            CommitChanges();

            return((VSCodeNamespace)cn.UserData[CodeKey]);
        }
示例#2
0
		///-------------------------------------------------------------------------------------------------------------
		/// <summary>
		///	 Recursively searches the CodeElements for the specified class
		/// </summary>
		///-------------------------------------------------------------------------------------------------------------
		protected virtual CodeClass FindClass(CodeElements codeElements, string className)
		{
			if (codeElements != null && !string.IsNullOrEmpty(className))
			{
				foreach (CodeElement codeElement in codeElements)
				{
					vsCMElement kind = codeElement.Kind;
					if (kind == vsCMElement.vsCMElementClass)
					{
						CodeClass codeClass = codeElement as CodeClass;
						if (codeClass != null && string.Compare(codeClass.FullName, className, StringComparison.Ordinal) == 0)
						{
							return codeClass;
						}
					}
					else if (kind == vsCMElement.vsCMElementNamespace)
					{
						EnvDTE.CodeNamespace codeNamespace = codeElement as EnvDTE.CodeNamespace;
						if (codeNamespace != null)
						{
							CodeClass codeClass = FindClass(codeNamespace.Children, className);
							if (codeClass != null)
							{
								return codeClass;
							}
						}
					}
				}
			}
			return null;
		}
示例#3
0
        public static void WalkNamespace(EnvDTE.CodeNamespace cns, string indent)
        {
            doNamespace(cns, indent);
            foreach (EnvDTE.CodeElement codeElem in cns.Members)
            {
                switch (codeElem.Kind)
                {
                case EnvDTE.vsCMElement.vsCMElementNamespace:
                    WalkNamespace((CodeNamespace)codeElem, indent + "...");
                    break;

                case EnvDTE.vsCMElement.vsCMElementClass:
                    WalkClass((CodeClass)codeElem, indent + "...");
                    break;

                case EnvDTE.vsCMElement.vsCMElementInterface:
                    WalkInterface((CodeInterface)codeElem, indent + "...");
                    break;

                default:
                    doCodeElement(codeElem, indent);
                    break;
                }
            }
        }
        public override void CollectProjectClasses(SolutionProject sp)
        {
            base.CollectProjectClasses(sp);
            if (sp == null)
            {
                return;
            }
            if (sp.ProjectRef == null)
            {
                return;
            }

            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();



            if (sp.ProjectRef.CodeModel == null)
            {
                return;
            }
            foreach (EnvDTE.CodeElement ce in sp.ProjectRef.CodeModel.CodeElements)
            {
                if (ce.Kind == EnvDTE.vsCMElement.vsCMElementClass)
                {
                    if (ce.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject)
                    {
                        if ((ce as CodeClass).IsDerivedFrom["System.Data.Entity.DbContext"] || (ce as CodeClass).IsDerivedFrom["Microsoft.EntityFrameworkCore.DbContext"])
                        {
                            SolutionCodeElement sce = new SolutionCodeElement()
                            {
                                CodeElementName     = ce.Name,
                                CodeElementFullName = ce.FullName,
                                CodeElementRef      = ce
                            };
                            ComboItemsSourceCodeElements.Add(sce);
                        }
                    }
                }
                else
                {
                    if (ce.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
                    {
                        EnvDTE.CodeNamespace cn = (EnvDTE.CodeNamespace)ce;
                        InternalCollectProjectClasses(cn);
                    }
                }
            }
        }
示例#5
0
        private EnvDTE.CodeNamespace GetNamespace(EnvDTE.Project f, string name)
        {
            var namespaceParts = name.Split('.');

            EnvDTE.CodeNamespace current = null;
            foreach (var part in namespaceParts)
            {
                if (current == null)
                {
                    current = f.CodeModel.CodeElements.OfType <EnvDTE.CodeNamespace>().First(n => n.Name == part);
                    continue;
                }
                current = current.Members.OfType <EnvDTE.CodeNamespace>().First(n => n.Name == part);
            }
            return(current);
        }
 protected bool InternalCollectProjectClasses(EnvDTE.CodeNamespace parentCodeNamespace)
 {
     foreach (EnvDTE.CodeElement ce in parentCodeNamespace.Members)
     {
         if (ce.Kind == EnvDTE.vsCMElement.vsCMElementClass)
         {
             if (ce.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject)
             {
                 if ((ce as CodeClass).IsDerivedFrom["System.Data.Entity.DbContext"] || (ce as CodeClass).IsDerivedFrom["Microsoft.EntityFrameworkCore.DbContext"])
                 {
                     //////// additional checkup here
                     SolutionCodeElement sce = new SolutionCodeElement()
                     {
                         CodeElementName     = ce.Name,
                         CodeElementFullName = ce.FullName,
                         CodeElementRef      = ce
                     };
                     ComboItemsSourceCodeElements.Add(sce);
                 }
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             if (ce.Kind == EnvDTE.vsCMElement.vsCMElementNamespace)
             {
                 EnvDTE.CodeNamespace cn = (EnvDTE.CodeNamespace)ce;
                 if (!InternalCollectProjectClasses(cn))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
示例#7
0
 public static void doNamespace(EnvDTE.CodeNamespace cns, string indent)
 {
     Debug.WriteLine(indent + "namespace:" + cns.Name);
 }