Skip to content

Commit af41ce4

Browse files
committed
Fix static analysis errors in UnixEndPoint.
1 parent dca9c35 commit af41ce4

File tree

1 file changed

+24
-45
lines changed

1 file changed

+24
-45
lines changed

src/MySqlConnector/Utilities/UnixEndPoint.cs

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,22 @@ namespace MySqlConnector.Utilities
3939
{
4040
internal sealed class UnixEndPoint : EndPoint
4141
{
42-
string filename;
43-
44-
public UnixEndPoint (string filename)
42+
public UnixEndPoint(string filename)
4543
{
4644
if (filename is null)
47-
throw new ArgumentNullException ("filename");
48-
45+
throw new ArgumentNullException (nameof(filename));
4946
if (filename == "")
50-
throw new ArgumentException ("Cannot be empty.", "filename");
51-
this.filename = filename;
47+
throw new ArgumentException ("Cannot be empty.", nameof(filename));
48+
Filename = filename;
5249
}
5350

54-
public string Filename {
55-
get {
56-
return(filename);
57-
}
58-
set {
59-
filename=value;
60-
}
61-
}
51+
private UnixEndPoint() => Filename = "";
6252

63-
public override AddressFamily AddressFamily {
64-
get { return AddressFamily.Unix; }
65-
}
53+
public string Filename { get; }
6654

67-
public override EndPoint Create (SocketAddress socketAddress)
55+
public override AddressFamily AddressFamily => AddressFamily.Unix;
56+
57+
public override EndPoint Create(SocketAddress socketAddress)
6858
{
6959
/*
7060
* Should also check this
@@ -79,51 +69,40 @@ public override EndPoint Create (SocketAddress socketAddress)
7969
if (socketAddress.Size == 2) {
8070
// Empty filename.
8171
// Probably from RemoteEndPoint which on linux does not return the file name.
82-
UnixEndPoint uep = new UnixEndPoint ("a");
83-
uep.filename = "";
84-
return uep;
72+
return new UnixEndPoint();
8573
}
86-
int size = socketAddress.Size - 2;
87-
byte [] bytes = new byte [size];
88-
for (int i = 0; i < bytes.Length; i++) {
89-
bytes [i] = socketAddress [i + 2];
74+
var size = socketAddress.Size - 2;
75+
var bytes = new byte[size];
76+
for (var i = 0; i < bytes.Length; i++) {
77+
bytes[i] = socketAddress[i + 2];
9078
// There may be junk after the null terminator, so ignore it all.
91-
if (bytes [i] == 0) {
79+
if (bytes[i] == 0) {
9280
size = i;
9381
break;
9482
}
9583
}
9684

97-
string name = Encoding.UTF8.GetString (bytes, 0, size);
98-
return new UnixEndPoint (name);
85+
return new UnixEndPoint(Encoding.UTF8.GetString(bytes, 0, size));
9986
}
10087

101-
public override SocketAddress Serialize ()
88+
public override SocketAddress Serialize()
10289
{
103-
byte [] bytes = Encoding.UTF8.GetBytes (filename);
104-
SocketAddress sa = new SocketAddress (AddressFamily, 2 + bytes.Length + 1);
90+
var bytes = Encoding.UTF8.GetBytes(Filename);
91+
var sa = new SocketAddress(AddressFamily, 2 + bytes.Length + 1);
10592
// sa [0] -> family low byte, sa [1] -> family high byte
106-
for (int i = 0; i < bytes.Length; i++)
107-
sa [2 + i] = bytes [i];
93+
for (var i = 0; i < bytes.Length; i++)
94+
sa[2 + i] = bytes[i];
10895

10996
//NULL suffix for non-abstract path
11097
sa[2 + bytes.Length] = 0;
11198

11299
return sa;
113100
}
114101

115-
public override string ToString() {
116-
return(filename);
117-
}
102+
public override string ToString() => Filename;
118103

119-
public override int GetHashCode ()
120-
{
121-
return filename.GetHashCode ();
122-
}
104+
public override int GetHashCode() => Filename.GetHashCode ();
123105

124-
public override bool Equals (object? o)
125-
{
126-
return o is UnixEndPoint other && filename == other.filename;
127-
}
106+
public override bool Equals(object? o) => o is UnixEndPoint other && Filename == other.Filename;
128107
}
129108
}

0 commit comments

Comments
 (0)