ServiceClientGenerator.ProjectFileConfiguration.IsPlatformCodeFolder C# (CSharp) Method

IsPlatformCodeFolder() public method

Returns true if the last component of the specified folder path begins with '_' character, our convention for representing platform-specific code.
public IsPlatformCodeFolder ( string sourceFolder ) : bool
sourceFolder string
return bool
        public bool IsPlatformCodeFolder(string sourceFolder)
        {
            return GetPlatformFolderName(sourceFolder) != null;
        }

Usage Example

        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList <string> GetProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string serviceRootFolder)
        {
            // Start with the standard generated code folders for the platform
            var sourceCodeFolders = new List <string>
            {
                "Generated",
                @"Generated\Model",
                @"Generated\Model\Internal",
                @"Generated\Model\Internal\MarshallTransformations"
            };

            var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;

            sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            // Augment the returned folders with any custom subfolders already in existence. If the custom folder
            // ends with a recognised platform, only add it to the set if it matches the platform being generated
            if (Directory.Exists(serviceRootFolder))
            {
                var subFolders = Directory.GetDirectories(serviceRootFolder, "*", SearchOption.AllDirectories);
                if (subFolders.Any())
                {
                    foreach (var folder in subFolders)
                    {
                        var serviceRelativeFolder = folder.Substring(serviceRootFolder.Length);

                        if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
                        {
                            if (projectFileConfiguration.IsValidPlatformPathForProject(serviceRelativeFolder))
                            {
                                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                            }
                        }
                        else
                        {
                            sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                        }
                    }
                }
            }

            var foldersThatExist = new List <string>();

            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(serviceRootFolder, folder)))
                {
                    foldersThatExist.Add(folder);
                }
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return(foldersThatExist);
        }
All Usage Examples Of ServiceClientGenerator.ProjectFileConfiguration::IsPlatformCodeFolder