FromInt32() public static méthode

Creates a Number value from a int value
Requires an active script context.
public static FromInt32 ( int value ) : JsValue
value int The value to be converted
Résultat JsValue
        /// <summary>
        /// Makes a mapping of value from the host type to a script type
        /// </summary>
        /// <param name="value">The source value</param>
        /// <returns>The mapped value</returns>
        public JsValue MapToScriptType(object value)
        {
            if (value == null)
            {
                return(JsValue.Null);
            }

            if (value is Undefined)
            {
                return(JsValue.Undefined);
            }

            TypeCode typeCode = value.GetType().GetTypeCode();

            switch (typeCode)
            {
            case TypeCode.Boolean:
                return((bool)value ? JsValue.True : JsValue.False);

            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
                return(JsValue.FromInt32(Convert.ToInt32(value)));

            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                return(JsValue.FromDouble(Convert.ToDouble(value)));

            case TypeCode.Char:
            case TypeCode.String:
                return(JsValue.FromString((string)value));

            default:
                return(value is JsValue ? (JsValue)value : GetOrCreateScriptObject(value));
            }
        }
        private static JsValue CreateErrorFromWrapperException(WrapperException exception)
        {
            var         originalException = exception.InnerException as JsException;
            JsErrorCode errorCode         = originalException != null ?
                                            originalException.ErrorCode : JsErrorCode.NoError;
            string description = exception.Description;

            JsValue innerErrorValue = JsErrorHelpers.CreateError(description);

            innerErrorValue.SetProperty("description", JsValue.FromString(description), true);

            JsValue metadataValue = JsValue.CreateObject();

            var scriptException = exception as WrapperScriptException;

            if (scriptException != null)
            {
                string type         = scriptException.Type;
                string documentName = scriptException.DocumentName;
                int    lineNumber   = scriptException.LineNumber;
                if (lineNumber > 0)
                {
                    lineNumber--;
                }
                int columnNumber = scriptException.ColumnNumber;
                if (columnNumber > 0)
                {
                    columnNumber--;
                }
                string sourceFragment = scriptException.SourceFragment;

                innerErrorValue.SetProperty("name", JsValue.FromString(type), true);

                var runtimeException = scriptException as WrapperRuntimeException;
                if (runtimeException != null)
                {
                    var    errorNumber = (int)errorCode;
                    string callStack   = runtimeException.CallStack;
                    string messageWithTypeAndCallStack = CoreErrorHelpers.GenerateScriptErrorMessage(type,
                                                                                                     description, callStack);

                    innerErrorValue.SetProperty("number", JsValue.FromInt32(errorNumber), true);
                    if (!string.IsNullOrWhiteSpace(callStack))
                    {
                        innerErrorValue.SetProperty("stack", JsValue.FromString(messageWithTypeAndCallStack), true);
                    }
                }
                else
                {
                    innerErrorValue.SetProperty("url", JsValue.FromString(documentName), true);
                    innerErrorValue.SetProperty("line", JsValue.FromInt32(lineNumber), true);
                    innerErrorValue.SetProperty("column", JsValue.FromInt32(columnNumber), true);
                    innerErrorValue.SetProperty("source", JsValue.FromString(sourceFragment), true);
                }

                metadataValue.SetProperty("url", JsValue.FromString(documentName), true);
                metadataValue.SetProperty("line", JsValue.FromInt32(lineNumber), true);
                metadataValue.SetProperty("column", JsValue.FromInt32(columnNumber), true);
                metadataValue.SetProperty("source", JsValue.FromString(sourceFragment), true);
            }

            innerErrorValue.SetProperty("metadata", metadataValue, true);

            JsValue errorValue = JsErrorHelpers.CreateError(description);

            errorValue.SetProperty("innerException", innerErrorValue, true);

            return(errorValue);
        }