public static IEnumerable<string> GetPatternsCollection(JsonObject rawProject, string projectDirectory, string projectFilePath, string propertyName, IEnumerable<string> defaultPatterns = null, bool literalPath = false) { defaultPatterns = defaultPatterns ?? Enumerable.Empty<string>(); try { if (!rawProject.Keys.Contains(propertyName)) { return CreateCollection(projectDirectory, propertyName, defaultPatterns, literalPath); } var valueInString = rawProject.ValueAsString(propertyName); if (valueInString != null) { return CreateCollection(projectDirectory, propertyName, new string[] { valueInString }, literalPath); } var valuesInArray = rawProject.ValueAsStringArray(propertyName); if (valuesInArray != null) { return CreateCollection(projectDirectory, propertyName, valuesInArray.Select(s => s.ToString()), literalPath); } } catch (Exception ex) { throw FileFormatException.Create(ex, rawProject.Value(propertyName), projectFilePath); } throw FileFormatException.Create("Value must be either string or array.", rawProject.Value(propertyName), projectFilePath); }
/// <summary> /// Parse a Json object which represents project configuration for a specified framework /// </summary> /// <param name="frameworkKey">The name of the framework</param> /// <param name="frameworkValue">The Json object represent the settings</param> /// <returns>Returns true if it successes.</returns> private bool BuildTargetFrameworkNode(Project project, string frameworkKey, JsonObject frameworkValue) { // If no compilation options are provided then figure them out from the node var compilerOptions = GetCompilationOptions(frameworkValue) ?? new CompilerOptions(); var frameworkName = FrameworkNameHelper.ParseFrameworkName(frameworkKey); // If it's not unsupported then keep it if (frameworkName == VersionUtility.UnsupportedFrameworkName) { // REVIEW: Should we skip unsupported target frameworks return false; } // Add the target framework specific define var defines = new HashSet<string>(compilerOptions.Defines ?? Enumerable.Empty<string>()); var frameworkDefinition = Tuple.Create(frameworkKey, frameworkName); var frameworkDefine = FrameworkNameHelper.MakeDefaultTargetFrameworkDefine(frameworkDefinition); if (!string.IsNullOrEmpty(frameworkDefine)) { defines.Add(frameworkDefine); } compilerOptions.Defines = defines; var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, Dependencies = new List<LibraryDependency>() }; var frameworkDependencies = new List<LibraryDependency>(); PopulateDependencies( project.ProjectFilePath, frameworkDependencies, frameworkValue, "dependencies", isGacOrFrameworkReference: false); var frameworkAssemblies = new List<LibraryDependency>(); PopulateDependencies( project.ProjectFilePath, frameworkAssemblies, frameworkValue, "frameworkAssemblies", isGacOrFrameworkReference: true); frameworkDependencies.AddRange(frameworkAssemblies); targetFrameworkInformation.Dependencies = frameworkDependencies; targetFrameworkInformation.WrappedProject = frameworkValue.ValueAsString("wrappedProject"); var binNode = frameworkValue.ValueAsJsonObject("bin"); if (binNode != null) { targetFrameworkInformation.AssemblyPath = binNode.ValueAsString("assembly"); targetFrameworkInformation.PdbPath = binNode.ValueAsString("pdb"); } project._compilerOptionsByFramework[frameworkName] = compilerOptions; project._targetFrameworks[frameworkName] = targetFrameworkInformation; return true; }
private static bool TryGetStringEnumerable(JsonObject parent, string property, out IEnumerable<string> result) { var collection = new List<string>(); var valueInString = parent.ValueAsString(property); if (valueInString != null) { collection.Add(valueInString); } else { var valueInArray = parent.ValueAsStringArray(property); if (valueInArray != null) { collection.AddRange(valueInArray); } else { result = null; return false; } } result = collection.SelectMany(value => value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)); return true; }