From 26415c014397c463f2954e0bd9ff742110c5ea75 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 1 Mar 2021 23:12:33 -0800 Subject: Rename AccessModifiers and optimize its serialization --- src/WixToolset.Data/AccessModifier.cs | 82 ++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 5 deletions(-) (limited to 'src/WixToolset.Data/AccessModifier.cs') diff --git a/src/WixToolset.Data/AccessModifier.cs b/src/WixToolset.Data/AccessModifier.cs index 64f29f26..191558b5 100644 --- a/src/WixToolset.Data/AccessModifier.cs +++ b/src/WixToolset.Data/AccessModifier.cs @@ -2,26 +2,98 @@ namespace WixToolset.Data { + using System; + public enum AccessModifier { /// - /// Indicates the identifier is publicly visible to all other sections. + /// Indicates the identifier is globally visible to all other sections. /// - Public, + Global, + [Obsolete] + Public = Global, /// /// Indicates the identifier is visible only to sections in the same library. /// - Internal, + Library, + [Obsolete] + Internal = Library, /// /// Indicates the identifier is visible only to sections in the same source file. /// - Protected, + File, + [Obsolete] + Protected = File, /// /// Indicates the identifiers is visible only to the section where it is defined. /// - Private, + Section, + [Obsolete] + Private = Section, + } + + /// + /// Extensions for converting AccessModifier to and from strings optimally. + /// + public static class AccessModifierExtensions + { + /// + /// Converts a string to an AccessModifier. + /// + /// String value to convert. + /// Converted AccessModifier. + public static AccessModifier AsAccessModifier(this string access) + { + switch (access) + { + case "global": + case "public": + return AccessModifier.Global; + + case "library": + case "internal": + return AccessModifier.Library; + + case "file": + case "protected": + return AccessModifier.File; + + case "section": + case "private": + return AccessModifier.Section; + + default: + throw new ArgumentException($"Unknown AccessModifier: {access}", nameof(access)); + } + } + + /// + /// Converts an AccessModifier to a string. + /// + /// AccessModifier value to convert. + /// Converted string. + public static string AsString(this AccessModifier access) + { + switch (access) + { + case AccessModifier.Global: + return "global"; + + case AccessModifier.Library: + return "library"; + + case AccessModifier.File: + return "file"; + + case AccessModifier.Section: + return "section"; + + default: + throw new ArgumentException($"Unknown AccessModifier: {access}", nameof(access)); + } + } } } -- cgit v1.2.3-55-g6feb