/// <summary>
        /// Creates a new ClrInstanceTypeWrapper object.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="type"> The CLR type to wrap. </param>
        private ClrInstanceTypeWrapper(ScriptEngine engine, Type type)
            : base(engine, GetPrototypeObject(engine, type))
        {
            this.WrappedType = type;

            // Populate the fields, properties and methods.
            ClrStaticTypeWrapper.PopulateMembers(this, type, BindingFlags.Instance);
        }
        //     INITIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Retrieves a ClrStaticTypeWrapper object from the cache, if possible, or creates it
        /// otherwise.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="type"> The CLR type to wrap. </param>
        public static ClrStaticTypeWrapper FromCache(ScriptEngine engine, Type type)
        {
            ClrStaticTypeWrapper cachedInstance;
            if (engine.StaticTypeWrapperCache.TryGetValue(type, out cachedInstance) == true)
                return cachedInstance;
            var newInstance = new ClrStaticTypeWrapper(engine, type);
            engine.StaticTypeWrapperCache.Add(type, newInstance);
            return newInstance;
        }
        //     INITIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Retrieves a ClrStaticTypeWrapper object from the cache, if possible, or creates it
        /// otherwise.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="type"> The CLR type to wrap. </param>
        public static ClrStaticTypeWrapper FromCache(ScriptEngine engine, Type type)
        {
            if (!engine.EnableExposedClrTypes)
                throw new JavaScriptException(engine, "TypeError", "Unsupported type: CLR types are not supported.  Enable CLR types by setting the ScriptEngine's EnableExposedClrTypes property to true.");

            ClrStaticTypeWrapper cachedInstance;
            if (engine.StaticTypeWrapperCache.TryGetValue(type, out cachedInstance) == true)
                return cachedInstance;
            var newInstance = new ClrStaticTypeWrapper(engine, type);
            engine.StaticTypeWrapperCache.Add(type, newInstance);
            return newInstance;
        }
        //     INITIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Retrieves a ClrStaticTypeWrapper object from the cache, if possible, or creates it
        /// otherwise.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="type"> The CLR type to wrap. </param>
        public static ClrStaticTypeWrapper FromCache(ScriptEngine engine, Type type)
        {
            ClrStaticTypeWrapper cachedInstance;

            if (engine.StaticTypeWrapperCache.TryGetValue(type, out cachedInstance) == true)
            {
                return(cachedInstance);
            }
            var newInstance = new ClrStaticTypeWrapper(engine, type);

            engine.StaticTypeWrapperCache.Add(type, newInstance);
            return(newInstance);
        }
Exemple #5
0
 /// <summary>
 /// Returns an object instance to serve as the next object in the prototype chain.
 /// </summary>
 /// <param name="engine"> The associated script engine. </param>
 /// <param name="type"> The CLR type to wrap. </param>
 /// <returns> The next object in the prototype chain. </returns>
 private static ObjectInstance GetPrototypeObject(ScriptEngine engine, Type type)
 {
     if (engine == null)
     {
         throw new ArgumentNullException(nameof(engine));
     }
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (type.BaseType == null)
     {
         return(null);
     }
     return(ClrStaticTypeWrapper.FromCache(engine, type.BaseType));
 }
Exemple #6
0
        //     INITIALIZATION
        //_________________________________________________________________________________________

        /// <summary>
        /// Retrieves a ClrStaticTypeWrapper object from the cache, if possible, or creates it
        /// otherwise.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="type"> The CLR type to wrap. </param>
        public static ClrStaticTypeWrapper FromCache(ScriptEngine engine, Type type)
        {
            if (!engine.EnableExposedClrTypes)
            {
                throw new JavaScriptException(ErrorType.TypeError, "Unsupported type: CLR types are not supported.  Enable CLR types by setting the ScriptEngine's EnableExposedClrTypes property to true.");
            }

            ClrStaticTypeWrapper cachedInstance;

            if (engine.StaticTypeWrapperCache.TryGetValue(type, out cachedInstance) == true)
            {
                return(cachedInstance);
            }
            var newInstance = new ClrStaticTypeWrapper(engine, type);

            engine.StaticTypeWrapperCache.Add(type, newInstance);
            return(newInstance);
        }
Exemple #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="clrStaticTypeWrapper">The displayed type</param>
 public ClrStaticTypeWrapperDebugView(ClrStaticTypeWrapper clrStaticTypeWrapper)
 {
     this.clrStaticTypeWrapper = clrStaticTypeWrapper;
 }