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); }
public static IDictionary<string, string> ReadNamedResources(JsonObject rawProject, string projectFilePath) { if (!rawProject.Keys.Contains("namedResource")) { return new Dictionary<string, string>(); } var namedResourceToken = rawProject.ValueAsJsonObject("namedResource"); if (namedResourceToken == null) { throw FileFormatException.Create("Value must be object.", rawProject.Value("namedResource"), projectFilePath); } var namedResources = new Dictionary<string, string>(); foreach (var namedResourceKey in namedResourceToken.Keys) { var resourcePath = namedResourceToken.ValueAsString(namedResourceKey); if (resourcePath == null) { throw FileFormatException.Create("Value must be string.", namedResourceToken.Value(namedResourceKey), projectFilePath); } if (resourcePath.Value.Contains("*")) { throw FileFormatException.Create("Value cannot contain wildcards.", resourcePath, projectFilePath); } var resourceFileFullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(projectFilePath), resourcePath)); if (namedResources.ContainsKey(namedResourceKey)) { throw FileFormatException.Create( string.Format("The named resource {0} already exists.", namedResourceKey), resourcePath, projectFilePath); } namedResources.Add( namedResourceKey, resourceFileFullPath); } return namedResources; }
private static List<DiagnosticMessage> ValueAsCompilationMessages(JsonObject obj, string key) { var messages = new List<DiagnosticMessage>(); var arrayValue = obj.Value(key) as JsonArray; for (int i = 0; i < arrayValue.Length; i++) { var item = arrayValue[i] as JsonObject; var message = new DiagnosticMessage( item.ValueAsString(nameof(DiagnosticMessage.ErrorCode)), item.ValueAsString(nameof(DiagnosticMessage.Message)), item.ValueAsString(nameof(DiagnosticMessage.FormattedMessage)), item.ValueAsString(nameof(DiagnosticMessage.SourceFilePath)), (DiagnosticMessageSeverity)item.ValueAsInt(nameof(DiagnosticMessage.Severity)), item.ValueAsInt(nameof(DiagnosticMessage.StartColumn)), item.ValueAsInt(nameof(DiagnosticMessage.StartLine)), item.ValueAsInt(nameof(DiagnosticMessage.EndColumn)), item.ValueAsInt(nameof(DiagnosticMessage.EndLine))); messages.Add(message); } return messages; }