/// <summary> /// Tries to create an instance of struct which is either specified by <paramref name="assemblyLocation"/> and <paramref name="typeName"/> pair, or by assembly-qualified <paramref name="typeName"/>. /// </summary> /// <typeparam name="T">The type of the struct.</typeparam> /// <param name="loader">This <see cref="ExplicitAssemblyLoader"/>.</param> /// <param name="typeName">The name of the type. It should be the full name if <paramref name="assemblyLocation"/> is specified, and assembly-qualified name if <paramref name="assemblyLocation"/> is not specified. It can be <c>null</c> if <paramref name="assemblyLocation"/> is specified; in that case the first suitable type is returned.</param> /// <param name="assemblyLocation">The location of the assembly file. If it is specified, this <see cref="ExplicitAssemblyLoader"/> is not used. Instead, the type is loaded using <see cref="Type.GetType(string, bool)"/>, if <paramref name="typeName"/> is specified.</param> /// <param name="instanceCreator">The optional callback to create an instance once the type has been acquired. By default, the <see cref="Activator.CreateInstance(Type)"/> is used.</param> /// <returns>An instance of type <typeparamref name="T"/>, or <c>null</c>.</returns> /// <exception cref="NullReferenceException">If <paramref name="assemblyLocation"/> is specified, and this <see cref="ExplicitAssemblyLoader"/> is <c>null</c>.</exception> public static T?TryLoadStructInstanceFromAssembly <T>( this ExplicitAssemblyLoader loader, String typeName, String assemblyLocation, Func <Type, Object> instanceCreator = null ) where T : struct { return((T?)(loader.TryLoadInstanceFromAssembly( typeName, assemblyLocation, additionalTypeCheck: t => !t.GetTypeInfo().IsClass, instanceCreator: instanceCreator ))); }
/// <summary> /// Tries to create an instance of class which is either specified by <paramref name="assemblyLocation"/> and <paramref name="typeName"/> pair, or by assembly-qualified <paramref name="typeName"/>. /// </summary> /// <typeparam name="T">The type of the class.</typeparam> /// <param name="loader">This <see cref="ExplicitAssemblyLoader"/>.</param> /// <param name="typeName">The name of the type. It should be the full name if <paramref name="assemblyLocation"/> is specified, and assembly-qualified name if <paramref name="assemblyLocation"/> is not specified. It can be <c>null</c> if <paramref name="assemblyLocation"/> is specified; in that case the first suitable type is returned.</param> /// <param name="assemblyLocation">The location of the assembly file. If it is specified, this <see cref="ExplicitAssemblyLoader"/> is not used. Instead, the type is loaded using <see cref="Type.GetType(string, bool)"/>, if <paramref name="typeName"/> is specified.</param> /// <param name="instanceCreator">The optional callback to create an instance once the type has been acquired. By default, the <see cref="Activator.CreateInstance(Type)"/> is used.</param> /// <returns>An instance of type <typeparamref name="T"/>, or <c>null</c>.</returns> /// <exception cref="NullReferenceException">If <paramref name="assemblyLocation"/> is specified, and this <see cref="ExplicitAssemblyLoader"/> is <c>null</c>.</exception> public static T TryLoadClassInstanceFromAssembly <T>( this ExplicitAssemblyLoader loader, String typeName, String assemblyLocation, Func <Type, Object> instanceCreator = null ) where T : class { return((T)(loader.TryLoadInstanceFromAssembly( typeName, assemblyLocation, requiredParentType: typeof(T).GetTypeInfo(), additionalTypeCheck: t => t.GetTypeInfo().IsClass, instanceCreator: instanceCreator ))); }