/// <summary> /// Creates an instance of the supplied <see cref="Type"/>. /// </summary> /// <param name="typeInstanciationContext">The <see cref="ITypeInstanciationContext"/> from which to create an instance.</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>The created instance.</returns> public Object CreateInstance(ITypeInstanciationContext typeInstanciationContext) { if (typeInstanciationContext == null) { throw new ArgumentNullException(nameof(typeInstanciationContext)); } var context = typeInstanciationContext as CollectionProxyingInstanciationContext; if (context != null) { return(this.CreateProxiedCollectionInstance(context)); } var instanciationContext = typeInstanciationContext as InstanceProxyingInstanciationContext; if (instanciationContext != null) { return(this.CreateProxiedInstance(instanciationContext)); } var defaultTypeInstanciationContext = typeInstanciationContext as DefaultTypeInstanciationContext; return(this.CreateDefaultInstance(defaultTypeInstanciationContext ?? typeInstanciationContext)); }
/// <summary> /// Creates a non proxied default instance of the <see cref="Type"/>. /// </summary> /// <param name="defaultTypeInstanciationContext">The <see cref="DefaultTypeInstanciationContext"/>.</param> /// <exception cref="ArgumentNullException">The value of '<paramref name="defaultTypeInstanciationContext"/>' cannot be null.</exception> /// <returns>The created instance.</returns> private Object CreateDefaultInstance([NotNull] ITypeInstanciationContext defaultTypeInstanciationContext) { if (defaultTypeInstanciationContext == null) { throw new ArgumentNullException(nameof(defaultTypeInstanciationContext)); } return(Activator.CreateInstance(defaultTypeInstanciationContext.RequestedType, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, null, null, null)); }