# all files / TypeScript.NET/dist/commonjs/System/Disposable/ DisposableBase.js

55% Statements 22/40
30% Branches 6/20
40% Functions 4/10
40.91% Lines 9/22

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58

    4×

    1×

    1×

    1×
    1×

    1×

    1×

    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    'use strict';

    var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

    function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var ObjectDisposedException_1 = require('./ObjectDisposedException');

    var DisposableBase = function () {
        function DisposableBase(_finalizer) {
            _classCallCheck(this, DisposableBase);

            this._finalizer = _finalizer;
            this._wasDisposed = false;
        }

        _createClass(DisposableBase, [{
            key: 'throwIfDisposed',
            value: function throwIfDisposed(message) {
                var objectName = arguments.length <= 1 || arguments[1] === undefined ? this._disposableObjectName : arguments[1];

                if (this._wasDisposed) throw new ObjectDisposedException_1.default(objectName, message);
                return true;
            }
        }, {
            key: 'dispose',
            value: function dispose() {
                var _ = this;
                if (!_._wasDisposed) {
                    _._wasDisposed = true;
                    try {
                        _._onDispose();
                    } finally {
                        if (_._finalizer) _._finalizer();
                    }
                }
            }
        }, {
            key: '_onDispose',
            value: function _onDispose() {}
        }, {
            key: 'wasDisposed',
            get: function get() {
                return this._wasDisposed;
            }
        }]);

        return DisposableBase;
    }();

    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = DisposableBase;
    //# sourceMappingURL=DisposableBase.js.map