internal static T InvokeWithDomain <T>(Func <AssemblyAttributeHelper, T> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            AppDomain domain = AppDomain.CreateDomain(nameof(AssemblyAttributeHelper));

            try
            {
                Type myType = typeof(AssemblyAttributeHelper);
                AssemblyAttributeHelper helper = (AssemblyAttributeHelper)domain.CreateInstanceFromAndUnwrap(myType.Assembly.Location, myType.FullName);
                var result = func(helper);
                return(result);
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }
예제 #2
0
        private string GetProductName(string entryPointFilePath)
        {
            string productName = !string.IsNullOrEmpty(LocalProduct) ? LocalProduct : Product;

            if (UseAssemblyProductName)
            {
                if (string.IsNullOrWhiteSpace(entryPointFilePath))
                {
                    throw new ArgumentException("Entrypoint not specified.", nameof(entryPointFilePath));
                }


                string assemblyProductName = AssemblyAttributeHelper.InvokeWithDomain(h => h.GetProductName(entryPointFilePath));
                if (!string.IsNullOrWhiteSpace(assemblyProductName))
                {
                    return(string.Format(CultureInfo.CurrentCulture, "{0} {1}", assemblyProductName, productName).Trim());
                }
            }

            return(productName);
        }