/// <summary> /// Creates a new scriptable wrapper for the specified object. Use this function instead /// of calling the JsObject constructor. /// </summary> /// <param name="wrappableObject">The object to wrap. It's type will be used as a key /// in a lookup for creating the correct wrappable type.</param> /// <returns>A new scriptable object that has been created with a type corresponding /// to the wrappableObject's type.</returns> public static J CreateWrapper <J>(object wrappableObject, ISvgScriptEngine scriptEngine) where J : class, IScriptableObject { // return null if we get null if (wrappableObject == null || scriptEngine == null) { return(null); } if (scriptEngine.ReferenceCache == null) { scriptEngine.ReferenceCache = new JsObjectReferenceCache(); } var jsRefCache = scriptEngine.ReferenceCache; // Check that the static table is built if (_jsMappedTypes == null || _jsMappedTypes.Count == 0) { InitializeWrapperTypes(); } // Do we already have a wrapper for this object? J jsObj = null; IScriptableObject jsObjBase = null; if (jsRefCache.TryGetValue(wrappableObject, out jsObjBase) && jsObjBase != null) { jsObj = jsObjBase as J; if (jsObj != null) { return(jsObj); } } // Return a new instance try { _wrapperArgs[0] = wrappableObject; _wrapperArgs[1] = scriptEngine; // Normal try { jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().Name, _wrapperArgs); jsRefCache.Add(wrappableObject, jsObjBase); return(jsObjBase as J); } catch (Exception) { // Try the ancestor jsObjBase = (IScriptableObject)_jsMappedTypes.CreateInstance(wrappableObject.GetType().BaseType.Name, _wrapperArgs); jsRefCache.Add(wrappableObject, jsObjBase); return(jsObjBase as J); } } catch (Exception e) { throw new SvgException(SvgExceptionType.SvgWrongTypeErr, "Could not create wrappable type for " + wrappableObject.GetType().FullName, e); } }
/// <summary> /// Removes the wrapper and base object key value pair. This function is called by the JsObject destructor. /// </summary> /// <param name="wrappableObject">The key object that was wrapped, to be removed.</param> public static void RemoveWrapper(object wrappableObject, ISvgScriptEngine scriptEngine) { // return null if we get null if (wrappableObject == null || scriptEngine == null) { return; } if (scriptEngine.ReferenceCache == null) { scriptEngine.ReferenceCache = new JsObjectReferenceCache(); } var jsRefCache = scriptEngine.ReferenceCache; // Remove it jsRefCache.Remove(wrappableObject.GetType().Name); }
public JsSvgVKernElement(ISvgVKernElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsProcessingInstruction(IProcessingInstruction baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsEntity(IEntity baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsNode(INode baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsComment(IComment baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsElement(IElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsCharacterData(ICharacterData baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgDefinitionSrcElement(ISvgDefinitionSrcElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgZoomEvent(ISvgZoomEvent baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgAnimateTransformElement(ISvgAnimateTransformElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgAnimateColorElement(ISvgAnimateColorElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgFontFaceNameElement(ISvgFontFaceNameElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsNamedNodeMap(INamedNodeMap baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgMetadataElement(ISvgMetadataElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsDomImplementation(IDomImplementation baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgForeignObjectElement(ISvgForeignObjectElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsAttr(IAttribute baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgCursorElement(ISvgCursorElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsText(IText baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgElementInstanceList(ISvgElementInstanceList baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsCDataSection(ICDataSection baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgColorProfileElement(ISvgColorProfileElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsNotation(INotation baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgColorProfileRule(ISvgColorProfileRule baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsEntityReference(IEntityReference baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsDomTimeStamp(IDomTimeStamp baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsDocument(IDocument baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public JsSvgMissingGlyphElement(ISvgMissingGlyphElement baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }