Beispiel #1
0
        /// <summary>
        /// Initialize a class fields
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="fileManager">File manager</param>
        /// <param name="options">Compilation options</param>
        private void InitializeFields(Func <IJsEngine> createJsEngineInstance, IFileManager fileManager, CompilationOptions options)
        {
            _createJsEngineInstance = createJsEngineInstance;
            _fileManager            = fileManager;
            _options = options ?? _defaultOptions;

#if MODERN_JSON_CONVERTER
            var jsonSerializerOptions = new JsonSerializerOptions();
#else
            var jsonSerializerOptions = new JsonSerializerSettings();
#endif
            var converters = jsonSerializerOptions.Converters;
            converters.Add(new CompilationOptionsConverter());
            converters.Add(new CompilationResultConverter(fileManager));

            _jsonSerializer = new UnifiedJsonSerializer(jsonSerializerOptions);
        }
Beispiel #2
0
        /// <summary>
        /// Destroys object
        /// </summary>
        public void Dispose()
        {
            if (_disposedFlag.Set())
            {
                if (_jsEngine != null)
                {
                    _jsEngine.RemoveVariable(FILE_MANAGER_VARIABLE_NAME);

                    _jsEngine.Dispose();
                    _jsEngine = null;
                }

                _jsonSerializer         = null;
                _options                = null;
                _fileManager            = null;
                _createJsEngineInstance = null;
            }
        }