System.Configuration.ClientConfigPaths.SetNamesAndVersion C# (CSharp) Метод

SetNamesAndVersion() приватный Метод

private SetNamesAndVersion ( string applicationFilename, Assembly exeAssembly, bool isHttp ) : void
applicationFilename string
exeAssembly System.Reflection.Assembly
isHttp bool
Результат void
        private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp) {
            Type        mainType = null;

            //
            // Get CompanyName, ProductName, and ProductVersion
            // First try custom attributes on the assembly.
            //
            if (exeAssembly != null) {
                object[] attrs = exeAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attrs != null && attrs.Length > 0) {
                    _companyName = ((AssemblyCompanyAttribute)attrs[0]).Company;
                    if (_companyName != null) {
                        _companyName = _companyName.Trim();
                    }
                }

                attrs = exeAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attrs != null && attrs.Length > 0) {
                    _productName = ((AssemblyProductAttribute)attrs[0]).Product;
                    if (_productName != null) {
                        _productName = _productName.Trim();
                    }
                }

                _productVersion = exeAssembly.GetName().Version.ToString();
                if (_productVersion != null) {
                    _productVersion = _productVersion.Trim();
                }
            }

            //
            // If we couldn't get custom attributes, try the Win32 file version
            // 
            if (!isHttp && (String.IsNullOrEmpty(_companyName) || String.IsNullOrEmpty(_productName) || String.IsNullOrEmpty(_productVersion))) {
                string versionInfoFileName = null;

                if (exeAssembly != null) {
                    MethodInfo entryPoint = exeAssembly.EntryPoint;
                    if (entryPoint != null) {
                        mainType = entryPoint.ReflectedType;
                        if (mainType != null) {
                            versionInfoFileName = mainType.Module.FullyQualifiedName;
                        }
                    }
                }

                if (versionInfoFileName == null) {
                    versionInfoFileName = applicationFilename;
                }

            }

            if (String.IsNullOrEmpty(_companyName) || String.IsNullOrEmpty(_productName)) {
                string  ns = null;
                if (mainType != null) {
                    ns = mainType.Namespace;
                }

                // Desperate measures for product name
                if (String.IsNullOrEmpty(_productName)) {
                    // Try the remainder of the namespace
                    if (ns != null) {
                        int lastDot = ns.LastIndexOf(".", StringComparison.Ordinal);
                        if (lastDot != -1 && lastDot < ns.Length - 1) {
                            _productName = ns.Substring(lastDot+1);
                        }
                        else {
                            _productName = ns;
                        }

                        _productName = _productName.Trim();
                    }

                    // Try the type of the entry assembly
                    if (String.IsNullOrEmpty(_productName) && mainType != null) {
                        _productName = mainType.Name.Trim();
                    }

                    // give up, return empty string
                    if (_productName == null) {
                        _productName = string.Empty;
                    }
                }

                // Desperate measures for company name
                if (String.IsNullOrEmpty(_companyName)) {
                    // Try the first part of the namespace
                    if (ns != null) {
                        int firstDot = ns.IndexOf(".", StringComparison.Ordinal);
                        if (firstDot != -1) {
                            _companyName = ns.Substring(0, firstDot);
                        }
                        else {
                            _companyName = ns;
                        }

                        _companyName = _companyName.Trim();
                    }

                    if (String.IsNullOrEmpty(_companyName)) {
                        _companyName = _productName;
                    }
                }
            }

            // Desperate measures for product version - assume 1.0
            if (String.IsNullOrEmpty(_productVersion)) {
                _productVersion = "1.0.0.0";
            }
        }