コード例 #1
0
        public object GetInstance()
        {
            if (objectStack.Count == 0)
            {
                CreateInstance(1);
            }
            object instance = objectStack.Pop();

            GetInstanceMethod?.Invoke(instance);
            return(instance);
        }
コード例 #2
0
        public object GetComponent(Type contract)
        {
            var instance = default(object);

            if (!GenericInstanceProviderMethod.TryGetValue(contract, out var genericMethod))
            {
                genericMethod = GetInstanceMethod.MakeGenericMethod(contract);
                GenericInstanceProviderMethod.Add(contract, genericMethod);
            }
            try {
                instance = genericMethod.Invoke(this, null);
            }
            catch (TargetInvocationException e) when(e.InnerException != null)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
            }
            return(instance);
        }