public static string ToJavaScript(object value, IEmitter emitter)
        {
            string s = null;

            if (value is double)
            {
                double d = (double)value;
                if (double.IsNaN(d))
                {
                    s = JS.Types.Number.NaN;
                }
                else if (double.IsPositiveInfinity(d))
                {
                    s = JS.Types.Number.Infinity;
                }
                else if (double.IsNegativeInfinity(d))
                {
                    s = JS.Types.Number.InfinityNegative;
                }
                else
                {
                    s = emitter.ToJavaScript(value);
                }
            }
            else if (value is float)
            {
                float f = (float)value;
                if (float.IsNaN(f))
                {
                    s = JS.Types.Number.NaN;
                }
                else if (float.IsPositiveInfinity(f))
                {
                    s = JS.Types.Number.Infinity;
                }
                else if (float.IsNegativeInfinity(f))
                {
                    s = JS.Types.Number.InfinityNegative;
                }
                else
                {
                    s = emitter.ToJavaScript(value);
                }
            }
            else if (value is char)
            {
                s = emitter.ToJavaScript((int)(char)value);
            }
            else if (value is decimal d)
            {
                var tmp = d.ToString(CultureInfo.InvariantCulture);
                s = JS.Types.SYSTEM_DECIMAL + "(" + AbstractEmitterBlock.DecimalConstant(d, emitter);

                int dot;
                if ((dot = tmp.IndexOf(".")) >= 0)
                {
                    s += ", " + tmp.Substring(dot + 1).Length;
                }

                s += ")";
            }
            else if (value is long)
            {
                s = JS.Types.System.Int64.NAME + "(" + AbstractEmitterBlock.LongConstant((long)value, emitter) + ")";
            }
            else if (value is ulong)
            {
                s = JS.Types.SYSTEM_UInt64 + "(" + AbstractEmitterBlock.ULongConstant((ulong)value, emitter) + ")";
            }
            else
            {
                s = emitter.ToJavaScript(value);
            }
            return(s);
        }
Example #2
0
        public static string ToJavaScript(object value, IEmitter emitter)
        {
            string s = null;

            if (value is double)
            {
                double d = (double)value;
                if (double.IsNaN(d))
                {
                    s = JS.Types.Number.NaN;
                }
                else if (double.IsPositiveInfinity(d))
                {
                    s = JS.Types.Number.Infinity;
                }
                else if (double.IsNegativeInfinity(d))
                {
                    s = JS.Types.Number.InfinityNegative;
                }
                else
                {
                    s = emitter.ToJavaScript(value);
                }
            }
            else if (value is float)
            {
                float f = (float)value;
                if (float.IsNaN(f))
                {
                    s = JS.Types.Number.NaN;
                }
                else if (float.IsPositiveInfinity(f))
                {
                    s = JS.Types.Number.Infinity;
                }
                else if (float.IsNegativeInfinity(f))
                {
                    s = JS.Types.Number.InfinityNegative;
                }
                else
                {
                    s = emitter.ToJavaScript(value);
                }
            }
            else if (value is char)
            {
                s = emitter.ToJavaScript((int)(char)value);
            }
            else if (value is decimal)
            {
                s = JS.Types.SYSTEM_DECIMAL + "(" + AbstractEmitterBlock.DecimalConstant((decimal)value, emitter) + ")";
            }
            else if (value is long)
            {
                s = JS.Types.System.Int64.NAME + "(" + AbstractEmitterBlock.LongConstant((long)value, emitter) + ")";
            }
            else if (value is ulong)
            {
                s = JS.Types.SYSTEM_UInt64 + "(" + AbstractEmitterBlock.ULongConstant((ulong)value, emitter) + ")";
            }
            else
            {
                s = emitter.ToJavaScript(value);
            }
            return(s);
        }