コード例 #1
0
        /// <summary>
        /// Get <see cref="ProjectMgr"/> as VSProject.
        /// Can be null.
        /// </summary>
        protected VSProject GetProject()
        {
            if ((_vsProject == null) && (ProjectMgr != null))
            {
                // get EnvDTE.Project from hierarchy
                object pVar;
                ErrorHandler.ThrowOnFailure(ProjectMgr.GetProperty(VSConstants.VSITEMID_ROOT,
                                                                   (int)__VSHPROPID.VSHPROPID_ExtObject, out pVar));
                var dteProject = pVar as EnvDTE.Project;
                if (dteProject == null)
                {
                    return(null);
                }

                // Get VSProject from EnvDTE.Project
                _vsProject = dteProject.Object as VSProject;
            }
            return(_vsProject);
        }