fix(di): do not use exceptions to detect if reflection is enabled

This commit is contained in:
vsavkin
2015-07-10 08:54:53 -07:00
parent 71c65b47f9
commit a6210466c7
7 changed files with 23 additions and 9 deletions

View File

@ -3,6 +3,7 @@ import {GetterFn, SetterFn, MethodFn} from './types';
import {List} from 'angular2/src/facade/collection';
export interface PlatformReflectionCapabilities {
isReflectionEnabled(): boolean;
factory(type: Type): Function;
interfaces(type: Type): List<any>;
parameters(type: Type): List<List<any>>;

View File

@ -7,6 +7,10 @@ import 'platform_reflection_capabilities.dart';
import 'package:angular2/src/facade/lang.dart';
class NoReflectionCapabilities implements PlatformReflectionCapabilities {
bool isReflectionEnabled() {
return false;
}
Function factory(Type type) {
throw "Cannot find reflection information on ${stringify(type)}";
}

View File

@ -8,6 +8,10 @@ import 'platform_reflection_capabilities.dart';
class ReflectionCapabilities implements PlatformReflectionCapabilities {
ReflectionCapabilities([metadataReader]) {}
bool isReflectionEnabled() {
return true;
}
Function factory(Type type) {
ClassMirror classMirror = reflectType(type);
MethodMirror ctor = classMirror.declarations[classMirror.simpleName];

View File

@ -15,6 +15,8 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; }
isReflectionEnabled(): boolean { return true; }
factory(t: Type): Function {
switch (t.length) {
case 0:

View File

@ -27,6 +27,8 @@ export class Reflector {
this.reflectionCapabilities = reflectionCapabilities;
}
isReflectionEnabled(): boolean { return this.reflectionCapabilities.isReflectionEnabled(); }
registerFunction(func: Function, funcInfo: StringMap<string, any>): void {
this._injectableInfo.set(func, funcInfo);
}