public static SilverBoxedInstance Box(object obj, SilverScope scope = null) { if (obj == null) { return null; } if (_boxCache.ContainsKey(obj)) { _boxCache[obj].BoxedScope.MergeWithScope(scope ?? new SilverScope()); return _boxCache[obj]; } var boxed = new SilverBoxedInstance(obj, scope ?? new SilverScope()); _boxCache[obj] = boxed; if (scope != null) { string name; SilverScope _scope = scope.SearchForObject(obj, out name); if (_scope != null) { _scope[name] = boxed; } } return boxed; }
public static SilverBoxedInstance BoxNoCache(object obj, SilverScope scope = null) { if (obj == null) { return null; } var boxed = new SilverBoxedInstance(obj, scope ?? new SilverScope()); if (scope != null) { string name; SilverScope _scope = scope.SearchForObject(obj, out name); if (_scope != null) { _scope[name] = boxed; } } return boxed; }
public static dynamic Unbox(SilverBoxedInstance obj) { _boxCache.Remove(obj.BoxedObject); return obj.BoxedObject; }