System.ComponentModel.LicenseManager.CreateWithContext C# (CSharp) Method

CreateWithContext() public static method

Creates an instance of the specified type with the specified arguments, using creationContext as the context in which the licensed instance can be used.

public static CreateWithContext ( Type type, System.ComponentModel.LicenseContext creationContext, object args ) : object
type Type
creationContext System.ComponentModel.LicenseContext
args object
return object
        public static object CreateWithContext(Type type, LicenseContext creationContext, object[] args)
        {
            object created = null;

            lock (s_internalSyncObject)
            {
                LicenseContext normal = CurrentContext;
                try
                {
                    CurrentContext = creationContext;
                    LockContext(s_selfLock);
                    try
                    {
                        created = SecurityUtils.SecureCreateInstance(type, args);
                    }
                    catch (TargetInvocationException e)
                    {
                        throw e.InnerException;
                    }
                }
                finally
                {
                    UnlockContext(s_selfLock);
                    CurrentContext = normal;
                }
            }

            return created;
        }

Same methods

LicenseManager::CreateWithContext ( Type type, System.ComponentModel.LicenseContext creationContext ) : object

Usage Example

Example #1
0
            // The CLR invokes this whenever a COM client invokes
            // IClassFactory::CreateInstance() or IClassFactory2::CreateInstanceLic()
            // on a managed managed that has a LicenseProvider custom attribute.
            //
            // If we are being entered because of a call to ICF::CreateInstance(),
            // fDesignTime will be "true".
            //
            // If we are being entered because of a call to ICF::CreateInstanceLic(),
            // fDesignTime will be "false" and bstrKey will point a non-null
            // license key.
            private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime)
            {
                Type type = Type.GetTypeFromHandle(rth);
                CLRLicenseContext licensecontext = new CLRLicenseContext(fDesignTime != 0 ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, type);

                if (fDesignTime == 0 && bstrKey != (IntPtr)0)
                {
                    licensecontext.SetSavedLicenseKey(type, Marshal.PtrToStringBSTR(bstrKey));
                }


                try {
                    return(LicenseManager.CreateWithContext(type, licensecontext));
                }
                catch (LicenseException lexp) {
                    throw new COMException(lexp.Message, CLASS_E_NOTLICENSED);
                }
            }
All Usage Examples Of System.ComponentModel.LicenseManager::CreateWithContext