String.Format JsClr

41 views
Skip to first unread message

Ben Martin

unread,
Dec 8, 2014, 5:09:41 AM12/8/14
to shar...@googlegroups.com
Is it possible to replace String.Format functions in JsClr with http://www.masterdata.se/r/string_format_for_javascript/?

Dan-el Khen

unread,
Dec 8, 2014, 6:03:14 AM12/8/14
to shar...@googlegroups.com
That looks interesting, if you think that the implementation is compliant with .NET, it's possible to try it out in a branch, and then merge it if it works.

D.
On Mon Dec 08 2014 at 11:09:42 AM Ben Martin <b...@trustorm.com.au> wrote:
Is it possible to replace String.Format functions in JsClr with http://www.masterdata.se/r/string_format_for_javascript/?

--
You received this message because you are subscribed to the Google Groups "SharpKit Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharpkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Martin

unread,
Dec 14, 2014, 9:42:30 PM12/14/14
to shar...@googlegroups.com
 
By overriding System.String.Format$$String$$Object$Array with the following code seems to do the job of switching to the new string.format  Is this the best way?


System.String.Format$$String$$Object$Array = function () {

                var args = new Array();

                var len = arguments.length;

                for (var i = 0; i < len; i++) {

                    if (Array.isArray(arguments[i])) {

                        var aLen = arguments[i].length;

                        for (var a = 0; a < aLen; a++) {
                            args.push(arguments[i][a]);
                        }

                    }
                    else {
                        args.push(arguments[i]);
                    }
                }

                return String.format.apply(null, args);
            };

Dan-el Khen

unread,
Dec 15, 2014, 4:35:43 AM12/15/14
to shar...@googlegroups.com
Nice! Well this overload is intended to be used when there's two parameters, string and object[], so I'm not sure why you're detecting each parameter and extract the items from it. On the other hand perhaps this code will support older versions of SharpKit where 'params' wasn't supported correctly. But all in all it looks fine, I wouldn't give you an alternative code without testing it, and it seems like you've made your tests :-)

D.
Reply all
Reply to author
Forward
0 new messages