ringcentral / RingCentral.Net

RingCentral SDK for .NET
MIT License
19 stars 26 forks source link

Enums aren't Enums #23

Closed TonyValenti closed 3 years ago

TonyValenti commented 4 years ago

Hi @tylerlong - Can you please update the SDK so that enum values are listed as actual enums instead of strings?

For example:

public enum AttachmentType {
  Unknown,
  AudioRecording,
  AudioTranscription,
  Text,
  SourceDocument,
  RenderedDocument,
  MmsAttachment
}

This will allow us to code more efficiently and in a less brittle way.

tylerlong commented 4 years ago

Known issue. Thanks for reporting.

tylerlong commented 3 years ago

The challenge is: C# enums are actually integers instead of strings. This article is helpful: https://www.bytefish.de/blog/enums_json_net.html

tylerlong commented 3 years ago

The idea is pretty good, but impractical. Example:

public class MethodInfo
    {
        /// <summary>
        /// Method identifier. The default value is 1 (Ground)
        /// </summary>
        public Id id { get; set; }
        public enum Id
        {
            1,
            2,
            3
        }

        /// <summary>
        /// Method name, corresponding to the identifier
        /// </summary>
        public Name name { get; set; }
        public enum Name
        {
            Ground,
            2 Day,
            Overnight
        }
    }

There are enum values which cannot be used as C# variable names: 1, 2, 3 & 2 Day.

We need to manually rename them and do mapping to the original json string.

Since all of the definitions classes are auto generated based on swagger spec, we prefer an automatic way to resolve the naming issue(otherwise, the code will break if spec changes). Unfortunately, there is no such a way.

tylerlong commented 3 years ago

I will close this issue for now since we won't implement it.