Author: jpobst Date: 2008-02-20 10:08:16 -0500 (Wed, 20 Feb 2008) New Revision: 96259
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog Log: 2008-02-20 Jonathan Pobst <[EMAIL PROTECTED]> * Application.cs: For CompanyName, ProductName, and ProductVersion, make sure we handle all three cases correctly: attribute is present, attribute is present but is an empty string, and attribute is not present. Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs =================================================================== --- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs 2008-02-20 15:01:40 UTC (rev 96258) +++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Application.cs 2008-02-20 15:08:16 UTC (rev 96259) @@ -209,16 +209,28 @@ public static string CompanyName { get { + string company = string.Empty; + Assembly assembly = Assembly.GetEntryAssembly (); + if (assembly == null) assembly = Assembly.GetCallingAssembly (); AssemblyCompanyAttribute[] attrs = (AssemblyCompanyAttribute[]) assembly.GetCustomAttributes (typeof(AssemblyCompanyAttribute), true); if (attrs != null && attrs.Length > 0) - return attrs [0].Company; + company = attrs [0].Company; - return assembly.GetName().Name; + // If there is no [AssemblyCompany], return the outermost namespace + // on Main () + if (company == null || company.Length == 0) + company = assembly.EntryPoint.DeclaringType.Namespace; + + // If that doesn't work, return the name of class containing Main () + if (company == null || company.Length == 0) + company = assembly.EntryPoint.DeclaringType.FullName; + + return company; } } @@ -262,7 +274,10 @@ public static string ProductName { get { + string name = string.Empty; + Assembly assembly = Assembly.GetEntryAssembly (); + if (assembly == null) assembly = Assembly.GetCallingAssembly (); @@ -270,17 +285,23 @@ assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), true); if (attrs != null && attrs.Length > 0) - return attrs [0].Product; + name = attrs [0].Product; - return assembly.GetName ().Name; + // If there is no [AssemblyProduct], return the name of class + // containing Main () + if (name == null || name.Length == 0) + name = assembly.EntryPoint.DeclaringType.FullName; + + return name; } } public static string ProductVersion { get { - String version; + String version = string.Empty; Assembly assembly = Assembly.GetEntryAssembly (); + if (assembly == null) assembly = Assembly.GetCallingAssembly (); @@ -288,18 +309,15 @@ Attribute.GetCustomAttribute (assembly, typeof (AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; + if (infoVersion != null) version = infoVersion.InformationalVersion; - else { - AssemblyFileVersionAttribute fileVersion = - Attribute.GetCustomAttribute (assembly, - typeof (AssemblyFileVersionAttribute)) - as AssemblyFileVersionAttribute; - if (fileVersion != null) - version = fileVersion.Version; - else - version = assembly.GetName ().Version.ToString (); - } + + // If [AssemblyInformationalVersion] is not present, it + // seems 1.0.0.0 is always returned, despite the documentation + if (version == null || version.Length == 0) + version = new Version (1, 0, 0, 0).ToString (); + return version; } } Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog =================================================================== --- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog 2008-02-20 15:01:40 UTC (rev 96258) +++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog 2008-02-20 15:08:16 UTC (rev 96259) @@ -1,3 +1,10 @@ +2008-02-20 Jonathan Pobst <[EMAIL PROTECTED]> + + * Application.cs: For CompanyName, ProductName, and ProductVersion, + make sure we handle all three cases correctly: attribute is present, + attribute is present but is an empty string, and attribute is not + present. + 2008-02-20 Ivan N. Zlatev <[EMAIL PROTECTED]> * PropertyGridView.cs: _______________________________________________ Mono-patches maillist - Mono-patches@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-patches