Example #1
0
        public static void ReturnObject(IInterface obj)
        {
            if (obj != null)
            {
                // TODO: Put the pool it belongs to inside IInterfaceImpl
                Stack <IInterfaceImpl> pool;
                if (pools.TryGetValue(obj.GetType(), out pool))
                {
                    IInterfaceImpl objImpl = (IInterfaceImpl)obj;
                    objImpl.ResetInterface();
                    objImpl.SetObj((UObjectRef)null);

                    // TODO: Set a cap on how many objects should be available in the stack?
                    pool.Push(objImpl);
                }
            }
        }
Example #2
0
        public static IInterface New(Type type, UObjectRef objRef)
        {
            Type implType;
            Stack <IInterfaceImpl> pool;

            if (interfaceTypes.TryGetValue(type, out implType) &&
                pools.TryGetValue(implType, out pool))
            {
                if (pool.Count > 0)
                {
                    IInterfaceImpl instance = pool.Pop();
                    instance.SetObj(objRef);
                    return(instance);
                }
                else
                {
                    // TODO: Use a faster way of constructing an instance
                    IInterfaceImpl instance = (IInterfaceImpl)Activator.CreateInstance(implType);
                    instance.SetObj(objRef);
                    return(instance);
                }
            }
            return(null);
        }