forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonSerializableDocumentId.cs
27 lines (24 loc) · 1.12 KB
/
JsonSerializableDocumentId.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json.Serialization;
namespace Microsoft.CodeAnalysis.ExternalAccess.Razor
{
/// <summary>
/// Represents a DocumentId that can be used by Razor for OOP services that communicate via System.Text.Json
/// </summary>
internal readonly record struct JsonSerializableDocumentId(
[property: JsonPropertyName("projectId")] Guid ProjectId,
[property: JsonPropertyName("id")] Guid Id)
{
public static implicit operator JsonSerializableDocumentId(DocumentId documentId)
{
return new JsonSerializableDocumentId(documentId.ProjectId.Id, documentId.Id);
}
public static implicit operator DocumentId(JsonSerializableDocumentId serializableDocumentId)
{
return DocumentId.CreateFromSerialized(CodeAnalysis.ProjectId.CreateFromSerialized(serializableDocumentId.ProjectId), serializableDocumentId.Id);
}
}
}