예제 #1
0
        public static KumaBoxedInstance Box(object obj, KumaScope scope = null)
        {
            if (obj == null)
            {
                return(null);
            }
            if (_boxCache.ContainsKey(obj))
            {
                _boxCache[obj].BoxedScope.MergeWithScope(scope ?? new KumaScope());
                return(_boxCache[obj]);
            }
            var boxed = new KumaBoxedInstance(obj, scope ?? new KumaScope());

            _boxCache[obj] = boxed;
            if (scope != null)
            {
                string name;
                var    _scope = scope.SearchForObject(obj, out name);
                if (_scope != null)
                {
                    _scope[name] = boxed;
                }
            }
            return(boxed);
        }
예제 #2
0
            public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
            {
                if (!(Value is KumaBoxedInstance) && Value.BackingObject != null)
                {
                    KumaBoxedInstance.SyncInstanceVariablesFrom(Value, Value.BackingObject);
                }
                var dmo = InteropBinder.GetMember.Bind(new InteropBinder.GetMember(binder.Name, Scope),
                                                       this);

                if (!(Value is KumaBoxedInstance) && Value.BackingObject != null)
                {
                    KumaBoxedInstance.SyncInstanceVariablesTo(Value, Value.BackingObject);
                }
                return(dmo);
            }
예제 #3
0
            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder,
                                                               params DynamicMetaObject[] args)
            {
                if (!(Value is KumaBoxedInstance) && Value.BackingObject != null)
                {
                    KumaBoxedInstance.SyncInstanceVariablesFrom(Value, Value.BackingObject);
                }
                var dmo =
                    InteropBinder.InvokeMember.Bind(
                        new InteropBinder.InvokeMember(binder.Name, binder.CallInfo, Scope), this, args);

                if (!(Value is KumaBoxedInstance) && Value.BackingObject != null)
                {
                    KumaBoxedInstance.SyncInstanceVariablesTo(Value, Value.BackingObject);
                }
                return(dmo);
            }
예제 #4
0
        public static KumaBoxedInstance BoxNoCache(object obj, KumaScope scope = null)
        {
            if (obj == null)
            {
                return(null);
            }
            var boxed = new KumaBoxedInstance(obj, scope ?? new KumaScope());

            if (scope != null)
            {
                string name;
                var    _scope = scope.SearchForObject(obj, out name);
                if (_scope != null)
                {
                    _scope[name] = boxed;
                }
            }
            return(boxed);
        }
예제 #5
0
 public static dynamic Unbox(KumaBoxedInstance obj)
 {
     _boxCache.Remove(obj.BoxedObject);
     return(obj.BoxedObject);
 }