Announcement

Collapse
No announcement yet.

Assigning string values to enums?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • txdv
    started a topic Assigning string values to enums?

    Assigning string values to enums?

    Saltarelle had the possibility to make convert enums to string values in method declarations.

    Is there a possibility to do the same in brdige.net?

  • Vladimir
    replied
    Yes, Enum attribute has several modes
    - Name - emit as reference (for example, BridgeTest.HttpVerb.Get)
    - Value - emit as value (inline value), for example Get will be emitted as 0
    - StringName - emit as string with lower first symbol, for example 'get'
    - StringNamePreserveCase - emit as string with preserving case, for example 'Get'
    - StringNameLowerCase - emit as lower case string, for example 'get'
    - StringNameUpperCase - emit as upper case string, for example 'GET'

    Name can be overriden by using Name attribute

    Leave a comment:


  • txdv
    replied
    If you just specify Emit.StringNameUpperCase, you don't have to specify the Name on a per enum field basis.

    Leave a comment:


  • Vladimir
    replied
    Yes, please see the following sample
    using System;
    using Bridge;
    using Bridge.Html5;
    
    namespace BridgeTest
    {
        [Enum(Emit.StringNameLowerCase)]
        [Ignore]
        public enum HttpVerb
        {
            [Name("GET")]
            Get = 0,
            [Name("POST")]
            Post = 1,
            [Name("PUT")]
            Put = 2,
            [Name("DELETE")]
            Delete = 3,
            [Name("HEAD")]
            Head = 4
        }
    
        public class App
        {
            [Ready]
            public static void Main()
            {
                var verb = HttpVerb.Post;
    
                switch (verb)
                {
                    case HttpVerb.Get:
                    case HttpVerb.Post:
                    case HttpVerb.Put:
                    case HttpVerb.Delete:
                    case HttpVerb.Head:
                        Console.Log(verb);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
        }
    }

    Leave a comment:


  • txdv
    replied
    You mean I can just use this like it is in Saltarelle? https://github.com/Saltarelle/Saltar...et/HttpVerb.cs
    Last edited by txdv; 2015-08-17 @ 09:01 PM.

    Leave a comment:


  • Vladimir
    replied
    Can you demonstrate a code which is valid in Saltarelle but you cannot use it in Bridge? Thanks

    Leave a comment:

Working...
X