ConvertToObject() public méthode

Converts a value to Object using regular JavaScript semantics
Requires an active script context.
public ConvertToObject ( ) : IeJsValue
Résultat IeJsValue
Exemple #1
0
        private object ToObject(IeJsValue value)
        {
            object result = value.HasExternalData ?
                            GCHandle.FromIntPtr(value.ExternalData).Target : value.ConvertToObject();

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Makes a mapping of value from the script type to a host type
        /// </summary>
        /// <param name="value">The source value</param>
        /// <returns>The mapped value</returns>
        private object MapToHostType(IeJsValue value)
        {
            JsValueType valueType = value.ValueType;
            IeJsValue   processedValue;
            object      result;

            switch (valueType)
            {
            case JsValueType.Null:
                result = null;
                break;

            case JsValueType.Undefined:
                result = Undefined.Value;
                break;

            case JsValueType.Boolean:
                processedValue = value.ConvertToBoolean();
                result         = processedValue.ToBoolean();
                break;

            case JsValueType.Number:
                processedValue = value.ConvertToNumber();
                result         = NumericHelpers.CastDoubleValueToCorrectType(processedValue.ToDouble());
                break;

            case JsValueType.String:
                processedValue = value.ConvertToString();
                result         = processedValue.ToString();
                break;

            case JsValueType.Object:
            case JsValueType.Function:
            case JsValueType.Error:
            case JsValueType.Array:
#if NETSTANDARD1_3
                result = ToObject(value);
#else
                processedValue = value.ConvertToObject();
                object obj = processedValue.ToObject();

                if (!TypeConverter.IsPrimitiveType(obj.GetType()))
                {
                    var hostObj = obj as HostObject;
                    result = hostObj != null ? hostObj.Target : obj;
                }
                else
                {
                    result = obj;
                }
#endif
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(result);
        }