private static JObject WriteLockFile(LockFile lockFile) { var json = new JObject(); json[VersionProperty] = new JValue(lockFile.Version); json[TargetsProperty] = WriteObject(lockFile.Targets, WriteTarget); json[LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary); json[ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup); if (lockFile.PackageFolders?.Any() == true) { json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem); } if (lockFile.Version >= 2) { if (lockFile.PackageSpec != null) { var writer = new JsonObjectWriter(); PackageSpecWriter.Write(lockFile.PackageSpec, writer); var packageSpec = writer.GetJObject(); json[PackageSpecProperty] = packageSpec; } } return(json); }
private static JObject GetJsonObject(PackageSpec packageSpec) { var writer = new JsonObjectWriter(); PackageSpecWriter.Write(packageSpec, writer); return(writer.GetJObject()); }
public static PackageSpec RoundTrip(this PackageSpec spec) { var writer = new JsonObjectWriter(); PackageSpecWriter.Write(spec, writer); var json = writer.GetJObject(); return(JsonPackageSpecReader.GetPackageSpec(json)); }
public void GetJObject() { _writer.WriteNameValue("a", 1); _writer.WriteNameValue("B", "C"); _writer.WriteNameArray("d", new[] { "e", "f" }); _writer.WriteObjectStart("g"); _writer.WriteNameValue("h", "i"); _writer.WriteObjectEnd(); var expectedJson = new JObject(); expectedJson["a"] = 1; expectedJson["B"] = "C"; expectedJson["d"] = new JArray("e", "f"); expectedJson["g"] = new JObject(); expectedJson["g"]["h"] = "i"; var actualJson = _writer.GetJObject(); Assert.Equal(expectedJson, actualJson); }
/// <summary> /// Clone a PackageSpec and underlying JObject. /// </summary> public PackageSpec Clone() { var writer = new JsonObjectWriter(); PackageSpecWriter.Write(this, writer); var json = writer.GetJObject(); var spec = JsonPackageSpecReader.GetPackageSpec(json); spec.Name = Name; spec.FilePath = FilePath; return(spec); }
private static JObject WriteLockFile(LockFile lockFile) { var json = new JObject { [VersionProperty] = new JValue(lockFile.Version), [TargetsProperty] = WriteObject(lockFile.Targets, WriteTarget), [LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary), [ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup) }; if (lockFile.PackageFolders?.Any() == true) { json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem); } if (lockFile.Version >= 2) { if (lockFile.PackageSpec != null) { var writer = new JsonObjectWriter(); PackageSpecWriter.Write(lockFile.PackageSpec, writer); var packageSpec = writer.GetJObject(); json[PackageSpecProperty] = packageSpec; } } if (lockFile.Version >= 3) { if (lockFile.LogMessages.Count > 0) { var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath; json[LogsProperty] = WriteLogMessages(lockFile.LogMessages, projectPath); } } return(json); }