Beispiel #1
0
        // Convert an object into a string.
        public static String ToString(Object value, bool explicitOK)
        {
            // Bail out immediately if it is already a string.
            String s = (value as String);

            if (s != null)
            {
                return(s);
            }

            // Handle conversions of null values.
            if (value == null)
            {
                return(explicitOK ? "undefined" : null);
            }
            else if (DBNull.IsDBNull(value))
            {
                return(explicitOK ? "null" : null);
            }

            // Use the standard "Object.ToString()" method.
            s = value.ToString();
            if (s != null)
            {
                return(s);
            }
            else
            {
                return(explicitOK ? "undefined" : null);
            }
        }
Beispiel #2
0
        // Determine if two JScript objects are equal.
        public static bool JScriptEquals(Object v1, Object v2)
        {
            // Handle the simple cases first.
            if (v1 is String && v2 is String)
            {
                return(((String)v1) == ((String)v2));
            }
            else if (v1 is double && v2 is double)
            {
                return(((double)v1) == ((double)v2));
            }
            else if (v1 is int && v2 is int)
            {
                return(((int)v1) == ((int)v2));
            }
            else if (v1 is bool && v2 is bool)
            {
                return(((bool)v1) == ((bool)v2));
            }
            else if (v1 == v2)
            {
                return(true);
            }

            // Is one of the values null?
            if (v1 == null || DBNull.IsDBNull(v1) || v1 is Missing
                        #if ECMA_COMPAT
                )
                        #else
                || v1 is System.Reflection.Missing)
                        #endif
            {
                return(v2 == null || DBNull.IsDBNull(v2) ||
                       v2 is Missing
                                #if ECMA_COMPAT
                       );