import { InternalError } from './InternalError' ; const classPrototypeUuidSymbol = Symbol . for ( 'TypeUuid.classPrototypeUuid' ) ; remarks public export class TypeUuid { private static _uuidRegExp : RegExp = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/ ; privateRemarks public static registerClass ( targetClass , typeUuid ) { if ( typeof targetClass !== 'function' ) { throw new Error ( 'The targetClass parameter must be a JavaScript class' ) ; } if ( ! TypeUuid . _uuidRegExp . test ( typeUuid ) ) { throw new Error ( `The type UUID must be specified as lowercase hexadecimal with dashes: "${ typeUuid }"` ) ; } const targetClassPrototype = targetClass . prototype ; if ( Object . hasOwnProperty . call ( targetClassPrototype , classPrototypeUuidSymbol ) ) { const existingUuid = targetClassPrototype [ classPrototypeUuidSymbol ] ; throw new InternalError ( `Cannot register the target class ${ targetClass . name || '' } typeUuid=${ typeUuid }` + ` because it was already registered with typeUuid=${ existingUuid }` ) ; } targetClassPrototype [ classPrototypeUuidSymbol ] = typeUuid ; } /**
     * Returns true if the `targetObject` is an instance of a JavaScript class that was previously
     * registered using the specified `typeUuid`.  Base classes are also considered.
     */ public static isInstanceOf ( targetObject , typeUuid ) { if ( targetObject === undefined || targetObject === null ) { return false ; } let objectPrototype = Object . getPrototypeOf ( targetObject ) ; while ( objectPrototype !== undefined && objectPrototype !== null ) { const registeredUuid = ( objectPrototype as any ) [ classPrototypeUuidSymbol ] ; if ( registeredUuid === typeUuid ) { return true ; } objectPrototype = Object . getPrototypeOf ( objectPrototype ) ; } return false ; } }