ServiceClientGenerator.SolutionFileCreator.GetProjectPlatformsFromFile C# (CSharp) Method

GetProjectPlatformsFromFile() static private method

static private GetProjectPlatformsFromFile ( string projectFile ) : IEnumerable
projectFile string
return IEnumerable
        static IEnumerable<string> GetProjectPlatformsFromFile(string projectFile)
        {
            var platforms = new List<string>();

            var content = File.ReadAllText(projectFile);
            var doc = new XmlDocument();
            doc.LoadXml(content);

            var searchPhrase = "$(Configuration)|$(Platform)";
            var propertyGroups = doc.GetElementsByTagName("PropertyGroup");
            foreach(XmlNode pg in propertyGroups)
            {
                var conditionAttrbiute = pg.Attributes["Condition"];
                if (conditionAttrbiute != null)
                {
                    var condition = conditionAttrbiute.Value;
                    if (condition.IndexOf(searchPhrase, StringComparison.Ordinal) >= 0)
                    {
                        var thirdQuote = condition.IndexOfNthOccurence('\'', 0, 3);
                        var fourthQuote = condition.IndexOf('\'', thirdQuote);
                        var platform = condition.Substring(thirdQuote, fourthQuote - thirdQuote);
                        // Project files use the string "AnyCPU", solution files use "Any CPU"
                        platform = platform.Replace("AnyCPU", "Any CPU");
                        platforms.Add(platform);
                    }
                }
            }

            return platforms;
        }
        static IEnumerable<string> GetProjectPlatforms(string projectName)