|
1 | 1 | using System; |
| 2 | +using System.IO; |
2 | 3 | using System.Reflection; |
3 | 4 | using System.Windows.Forms; |
4 | | -using CefSharp; |
5 | 5 |
|
6 | 6 | namespace CefSharp.WinForms.Example |
7 | 7 | { |
8 | 8 | partial class AboutBox : Form |
9 | 9 | { |
10 | | - public AboutBox() |
11 | | - { |
12 | | - InitializeComponent(); |
13 | | - Text = "About CefTest"; |
14 | | - labelProductName.Text = AssemblyProduct; |
15 | | - labelVersion.Text = String.Format("Version {0} ", Cef.CefSharpVersion); |
16 | | - labelCopyright.Text = AssemblyCopyright; |
17 | | - labelCompanyName.Text = AssemblyCompany; |
18 | | - textBoxDescription.Text = "CefSharp - .Net binding for Chromium\r\n\r\n" |
19 | | - + "Built on Chromium Embedded Framework\r\n" |
20 | | - + " - " + Cef.CefVersion + "\r\n" |
21 | | - + "Built on Chromium\r\n" |
22 | | - + " - " + Cef.ChromiumVersion + "\r\n"; |
23 | | - } |
24 | | - |
25 | | - #region Assembly Attribute Accessors |
| 10 | + private Assembly ExecutingAssembly { get; set; } |
26 | 11 |
|
27 | 12 | public string AssemblyTitle |
28 | 13 | { |
29 | 14 | get |
30 | 15 | { |
31 | | - object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
32 | | - if (attributes.Length > 0) |
| 16 | + var attributes = ExecutingAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
| 17 | + if (attributes.Length == 0) |
33 | 18 | { |
34 | | - AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; |
35 | | - if (titleAttribute.Title != "") |
36 | | - { |
37 | | - return titleAttribute.Title; |
38 | | - } |
| 19 | + return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); |
39 | 20 | } |
40 | | - return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); |
| 21 | + |
| 22 | + var titleAttribute = (AssemblyTitleAttribute)attributes[0]; |
| 23 | + return titleAttribute.Title != "" ? titleAttribute.Title : Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); |
41 | 24 | } |
42 | 25 | } |
43 | 26 |
|
44 | 27 | public string AssemblyVersion |
45 | 28 | { |
46 | 29 | get |
47 | 30 | { |
48 | | - return Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
| 31 | + return ExecutingAssembly.GetName().Version.ToString(); |
49 | 32 | } |
50 | 33 | } |
51 | 34 |
|
52 | 35 | public string AssemblyDescription |
53 | 36 | { |
54 | 37 | get |
55 | 38 | { |
56 | | - object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
57 | | - if (attributes.Length == 0) |
58 | | - { |
59 | | - return ""; |
60 | | - } |
61 | | - return ((AssemblyDescriptionAttribute)attributes[0]).Description; |
| 39 | + var attributes = ExecutingAssembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
| 40 | + return attributes.Length == 0 ? "" : ((AssemblyDescriptionAttribute)attributes[0]).Description; |
62 | 41 | } |
63 | 42 | } |
64 | 43 |
|
65 | 44 | public string AssemblyProduct |
66 | 45 | { |
67 | 46 | get |
68 | 47 | { |
69 | | - object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
70 | | - if (attributes.Length == 0) |
71 | | - { |
72 | | - return ""; |
73 | | - } |
74 | | - return ((AssemblyProductAttribute)attributes[0]).Product; |
| 48 | + var attributes = ExecutingAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
| 49 | + return attributes.Length == 0 ? "" : ((AssemblyProductAttribute)attributes[0]).Product; |
75 | 50 | } |
76 | 51 | } |
77 | 52 |
|
78 | 53 | public string AssemblyCopyright |
79 | 54 | { |
80 | 55 | get |
81 | 56 | { |
82 | | - object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
83 | | - if (attributes.Length == 0) |
84 | | - { |
85 | | - return ""; |
86 | | - } |
87 | | - return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; |
| 57 | + var attributes = ExecutingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
| 58 | + return attributes.Length == 0 ? "" : ((AssemblyCopyrightAttribute)attributes[0]).Copyright; |
88 | 59 | } |
89 | 60 | } |
90 | 61 |
|
91 | 62 | public string AssemblyCompany |
92 | 63 | { |
93 | 64 | get |
94 | 65 | { |
95 | | - object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
96 | | - if (attributes.Length == 0) |
97 | | - { |
98 | | - return ""; |
99 | | - } |
100 | | - return ((AssemblyCompanyAttribute)attributes[0]).Company; |
| 66 | + var attributes = ExecutingAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
| 67 | + return attributes.Length == 0 ? "" : ((AssemblyCompanyAttribute)attributes[0]).Company; |
101 | 68 | } |
102 | 69 | } |
103 | | - #endregion |
| 70 | + |
| 71 | + public AboutBox() |
| 72 | + { |
| 73 | + InitializeComponent(); |
| 74 | + ExecutingAssembly = Assembly.GetExecutingAssembly(); |
| 75 | + |
| 76 | + Text = "About CefTest"; |
| 77 | + labelProductName.Text = AssemblyProduct; |
| 78 | + labelVersion.Text = String.Format("Version {0} ", Cef.CefSharpVersion); |
| 79 | + labelCopyright.Text = AssemblyCopyright; |
| 80 | + labelCompanyName.Text = AssemblyCompany; |
| 81 | + textBoxDescription.Text = "CefSharp - .Net binding for Chromium\r\n\r\n" |
| 82 | + + "Built on Chromium Embedded Framework\r\n" |
| 83 | + + " - " + Cef.CefVersion + "\r\n" |
| 84 | + + "Built on Chromium\r\n" |
| 85 | + + " - " + Cef.ChromiumVersion + "\r\n"; |
| 86 | + } |
104 | 87 | } |
105 | 88 | } |
0 commit comments