| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Data |
| 4 | { |
| 5 | using System; |
| 6 | using System.Diagnostics; |
| 7 | using SimpleJson; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Class to define the identifier and access for a symbol. |
| 11 | /// </summary> |
| 12 | [DebuggerDisplay("{Access} {Id,nq}")] |
| 13 | public class Identifier |
| 14 | { |
| 15 | public static Identifier Invalid = new Identifier(AccessModifier.Section, (string)null); |
| 16 | |
| 17 | [Obsolete] |
| 18 | public Identifier(string id, AccessModifier access) |
| 19 | { |
| 20 | this.Id = id; |
| 21 | this.Access = access; |
| 22 | } |
| 23 | |
| 24 | public Identifier(AccessModifier access, string id) |
| 25 | { |
| 26 | this.Access = access; |
| 27 | this.Id = id; |
| 28 | } |
| 29 | |
| 30 | public Identifier(AccessModifier access, params string[] ids) |
| 31 | { |
| 32 | this.Access = access; |
| 33 | this.Id = String.Join("/", ids); |
| 34 | } |
| 35 | |
| 36 | public Identifier(AccessModifier access, params object[] ids) |
| 37 | { |
| 38 | this.Access = access; |
| 39 | this.Id = String.Join("/", ids); |
| 40 | } |
| 41 | |
| 42 | public Identifier(AccessModifier access, int id) |
| 43 | { |
| 44 | this.Access = access; |
| 45 | this.Id = id.ToString(); |
| 46 | } |
| 47 | |
| 48 | /// <summary> |
| 49 | /// Access modifier for a symbol. |
| 50 | /// </summary> |
| 51 | public AccessModifier Access { get; } |
| 52 | |
| 53 | /// <summary> |
| 54 | /// Identifier for the symbol. |
| 55 | /// </summary> |
| 56 | public string Id { get; } |
| 57 | |
| 58 | internal static Identifier Deserialize(JsonObject jsonObject) |
| 59 | { |
| 60 | var id = jsonObject.GetValueOrDefault<string>("id"); |
| 61 | var accessValue = jsonObject.GetValueOrDefault("access", "global"); |
| 62 | |
| 63 | return new Identifier(accessValue.AsAccessModifier(), id); |
| 64 | } |
| 65 | |
| 66 | internal JsonObject Serialize() |
| 67 | { |
| 68 | var jsonObject = new JsonObject |
| 69 | { |
| 70 | { "id", this.Id }, |
| 71 | { "access", this.Access.AsString() } |
| 72 | }; |
| 73 | |
| 74 | return jsonObject; |
| 75 | } |
| 76 | } |
| 77 | } |