FromObject() 공개 정적인 메소드

Creates a JavaScript value that is a projection of the passed in object
Requires an active script context.
public static FromObject ( object value ) : IeJsValue
value object The object to be projected
리턴 IeJsValue
예제 #1
0
        public override void EmbedHostType(string itemName, Type type)
        {
            InvokeScript(() =>
            {
#if NETSTANDARD1_3
                IeJsValue typeValue = CreateObjectFromType(type);
#else
                IeJsValue typeValue = IeJsValue.FromObject(new HostType(type, _engineMode));
#endif
                IeJsValue.GlobalObject.SetProperty(itemName, typeValue, true);
            });
        }
예제 #2
0
        /// <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>
        private IeJsValue MapToScriptType(object value)
        {
            if (value == null)
            {
                return(IeJsValue.Null);
            }

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

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

            switch (typeCode)
            {
            case TypeCode.Boolean:
                return((bool)value ? IeJsValue.True : IeJsValue.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(IeJsValue.FromInt32(Convert.ToInt32(value)));

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

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

            default:
#if NETSTANDARD1_3
                return(FromObject(value));
#else
                object processedValue = !TypeConverter.IsPrimitiveType(typeCode) ?
                                        new HostObject(value, _engineMode) : value;
                return(IeJsValue.FromObject(processedValue));
#endif
            }
        }