Skip to content

Commit f879b8b

Browse files
committed
#210. Cleanups in the spirit of ReSharper. The AboutBox class could need even more TLC actually…
1 parent 15b351c commit f879b8b

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed
Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,88 @@
11
using System;
2+
using System.IO;
23
using System.Reflection;
34
using System.Windows.Forms;
4-
using CefSharp;
55

66
namespace CefSharp.WinForms.Example
77
{
88
partial class AboutBox : Form
99
{
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; }
2611

2712
public string AssemblyTitle
2813
{
2914
get
3015
{
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)
3318
{
34-
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
35-
if (titleAttribute.Title != "")
36-
{
37-
return titleAttribute.Title;
38-
}
19+
return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
3920
}
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);
4124
}
4225
}
4326

4427
public string AssemblyVersion
4528
{
4629
get
4730
{
48-
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
31+
return ExecutingAssembly.GetName().Version.ToString();
4932
}
5033
}
5134

5235
public string AssemblyDescription
5336
{
5437
get
5538
{
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;
6241
}
6342
}
6443

6544
public string AssemblyProduct
6645
{
6746
get
6847
{
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;
7550
}
7651
}
7752

7853
public string AssemblyCopyright
7954
{
8055
get
8156
{
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;
8859
}
8960
}
9061

9162
public string AssemblyCompany
9263
{
9364
get
9465
{
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;
10168
}
10269
}
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+
}
10487
}
10588
}

CefSharp.WinForms.Example/AboutBox.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
<value>2.0</value>
113113
</resheader>
114114
<resheader name="reader">
115-
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116116
</resheader>
117117
<resheader name="writer">
118-
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
</root>

0 commit comments

Comments
 (0)