public object GetInstance() { if (objectStack.Count == 0) { CreateInstance(1); } object instance = objectStack.Pop(); GetInstanceMethod?.Invoke(instance); return(instance); }
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); }