@@ -39,32 +39,22 @@ namespace MySqlConnector.Utilities
39
39
{
40
40
internal sealed class UnixEndPoint : EndPoint
41
41
{
42
- string filename ;
43
-
44
- public UnixEndPoint ( string filename )
42
+ public UnixEndPoint ( string filename )
45
43
{
46
44
if ( filename is null )
47
- throw new ArgumentNullException ( "filename" ) ;
48
-
45
+ throw new ArgumentNullException ( nameof ( filename ) ) ;
49
46
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 ;
52
49
}
53
50
54
- public string Filename {
55
- get {
56
- return ( filename ) ;
57
- }
58
- set {
59
- filename = value ;
60
- }
61
- }
51
+ private UnixEndPoint ( ) => Filename = "" ;
62
52
63
- public override AddressFamily AddressFamily {
64
- get { return AddressFamily . Unix ; }
65
- }
53
+ public string Filename { get ; }
66
54
67
- public override EndPoint Create ( SocketAddress socketAddress )
55
+ public override AddressFamily AddressFamily => AddressFamily . Unix ;
56
+
57
+ public override EndPoint Create ( SocketAddress socketAddress )
68
58
{
69
59
/*
70
60
* Should also check this
@@ -79,51 +69,40 @@ public override EndPoint Create (SocketAddress socketAddress)
79
69
if ( socketAddress . Size == 2 ) {
80
70
// Empty filename.
81
71
// 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 ( ) ;
85
73
}
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 ] ;
90
78
// There may be junk after the null terminator, so ignore it all.
91
- if ( bytes [ i ] == 0 ) {
79
+ if ( bytes [ i ] == 0 ) {
92
80
size = i ;
93
81
break ;
94
82
}
95
83
}
96
84
97
- string name = Encoding . UTF8 . GetString ( bytes , 0 , size ) ;
98
- return new UnixEndPoint ( name ) ;
85
+ return new UnixEndPoint ( Encoding . UTF8 . GetString ( bytes , 0 , size ) ) ;
99
86
}
100
87
101
- public override SocketAddress Serialize ( )
88
+ public override SocketAddress Serialize ( )
102
89
{
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 ) ;
105
92
// 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 ] ;
108
95
109
96
//NULL suffix for non-abstract path
110
97
sa [ 2 + bytes . Length ] = 0 ;
111
98
112
99
return sa ;
113
100
}
114
101
115
- public override string ToString ( ) {
116
- return ( filename ) ;
117
- }
102
+ public override string ToString ( ) => Filename ;
118
103
119
- public override int GetHashCode ( )
120
- {
121
- return filename . GetHashCode ( ) ;
122
- }
104
+ public override int GetHashCode ( ) => Filename . GetHashCode ( ) ;
123
105
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 ;
128
107
}
129
108
}
0 commit comments