Announcement

Collapse
No announcement yet.

Incorrect code when using Template for a property and then class initializer.

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

    Incorrect code when using Template for a property and then class initializer.

    For example if I do this

        public class Test
        {
            public TimeSpan One {
                [Template("System.TimeSpan.parse({this}.One)")]
                get;
                [Template("{this}.One = Bridge.toString({value})")]
                set;
            }
    
            public TimeSpan Two {
                [Template("System.TimeSpan.parse({this}.Two)")]
                get;
                [Template("{this}.Two = Bridge.toString({value})")]
                set;
            }
    
            public TimeSpan Three {
                [Template("System.TimeSpan.parse({this}.Three)")]
                get;
                [Template("{this}.Three = Bridge.toString({value})")]
                set;
            }
        }
    then, this

                        var test = new Test()
                        {
                            One = TimeSpan.FromDays(1),
                            Two = TimeSpan.FromDays(2),
                            Three = TimeSpan.FromDays(3)
                        };
    the generated code is this

    test = ($t = new PortalScript.Components.Ring.Test()$t.One = Bridge.toString(System.TimeSpan.fromDays(1))$t.Two = Bridge.toString(System.TimeSpan.fromDays(2))$t.Three = Bridge.toString(System.TimeSpan.fromDays(3)), $t);
    It is missing commas between property initialization.
    However if I do this

                        test.One = TimeSpan.FromDays(1);
                        test.Two = TimeSpan.FromDays(2);
                        test.Three = TimeSpan.FromDays(3);
    Everything looks fine, semi-colons are there

                                                    test.One = Bridge.toString(System.TimeSpan.fromDays(1));
                                                    test.Two = Bridge.toString(System.TimeSpan.fromDays(2));
                                                    test.Three = Bridge.toString(System.TimeSpan.fromDays(3));
    The goal of using those Template attributes is to use TimeSpan property type in the C# code but string type in the JavaScript code. It is needed for a third-party library which expects these properties to be string representations of TimeSpan, such as "1.00:00:00". Please, let me know if there is a workaround besides using non-class initializer initialization.

    Thank you

    #2
    Hello alex4998 !

    Thanks for reporting it. No matter how I look at the report, I see a missing feature, to just prepent comma in object initializer within the code.

    I've created github issue #3886 to track this defect, and we'll post an update here as soon as we get this fixed upstream (when it will become slated to be fixed the coming release).

    Unfortunately at the moment I don't have a workaround that does not involve not using object initializer syntax.

    Comment

    Working...
    X