/// <summary>Creates an instance of the specified type with the specified arguments, given a context in which you can use the licensed instance.</summary>
/// <returns>An instance of the specified type with the given array of arguments.</returns>
/// <param name="type">A <see cref="T:System.Type" /> that represents the type to create. </param>
/// <param name="creationContext">A <see cref="T:System.ComponentModel.LicenseContext" /> that specifies when you can use the licensed instance. </param>
/// <param name="args">An array of type <see cref="T:System.Object" /> that represents the arguments for the type. </param>
public static object CreateWithContext(Type type, LicenseContext creationContext, object[] args)
{
object result = null;
object obj = LicenseManager.lockObject;
lock (obj)
{
object contextUser = new object();
LicenseContext currentContext = LicenseManager.CurrentContext;
LicenseManager.CurrentContext = creationContext;
LicenseManager.LockContext(contextUser);
try
{
result = Activator.CreateInstance(type, args);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
finally
{
LicenseManager.UnlockContext(contextUser);
LicenseManager.CurrentContext = currentContext;
}
}
return(result);
}