コード例 #1
0
        public ProjectItem FindProjectItem(object property, FindProjectProperty findProjectProperty, bool createIfNotFound = true)
        {
            ProjectItem        found;
            List <ProjectItem> projList = ProjectsList.ToList();

            switch (findProjectProperty)
            {
            case FindProjectProperty.UniqueName:
                var uniqueName = (string)property;
                found = projList.Find(item => item.UniqueName == uniqueName);
                break;

            case FindProjectProperty.FullName:
                var fullName = (string)property;
                found = projList.Find(item => item.FullName == fullName);
                break;

            case FindProjectProperty.ProjectObject:
                found = projList.Find(item => ReferenceEquals(item.StorageProject, property));
                break;

            case FindProjectProperty.UniqueNameProjectDefinition:
            {
                var projDef = (UniqueNameProjectDefinition)property;
                found = projList.Find(item => item.UniqueName == projDef.UniqueName &&
                                      item.Configuration == projDef.Configuration &&
                                      PlatformsIsEquals(item.Platform, projDef.Platform));
            }
            break;

            case FindProjectProperty.FullNameProjectDefinition:
            {
                var projDef = (FullNameProjectDefinition)property;
                found = projList.Find(item => item.FullName == projDef.FullName &&
                                      item.Configuration == projDef.Configuration &&
                                      PlatformsIsEquals(item.Platform, projDef.Platform));
            }
            break;

            default:
                throw new ArgumentOutOfRangeException("findProjectProperty");
            }

            if (found != null)
            {
                return(found);
            }

            Project proj;

            switch (findProjectProperty)
            {
            case FindProjectProperty.UniqueName:
                var uniqueName = (string)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == uniqueName);
                break;

            case FindProjectProperty.FullName:
                var fullName = (string)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == fullName);
                break;

            case FindProjectProperty.ProjectObject:
                proj = SolutionItem.StorageSolution.GetProject(item => ReferenceEquals(item, property));
                break;

            case FindProjectProperty.UniqueNameProjectDefinition:
            {
                var projDef = (UniqueNameProjectDefinition)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.UniqueName == projDef.UniqueName &&
                                                               item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration &&
                                                               PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
            }
            break;

            case FindProjectProperty.FullNameProjectDefinition:
            {
                var projDef = (FullNameProjectDefinition)property;
                proj = SolutionItem.StorageSolution.GetProject(item => item.FullName == projDef.FullName &&
                                                               item.ConfigurationManager.ActiveConfiguration.ConfigurationName == projDef.Configuration &&
                                                               PlatformsIsEquals(item.ConfigurationManager.ActiveConfiguration.PlatformName, projDef.Platform));
            }
            break;

            default:
                throw new ArgumentOutOfRangeException("findProjectProperty");
            }

            if (proj == null)
            {
                return(null);
            }

            var newProjItem = new ProjectItem(proj);

            ProjectsList.Add(newProjItem);
            return(newProjItem);
        }