Skip to content

Commit e7713c0

Browse files
committed
Code cleanup
1 parent 5dc45b7 commit e7713c0

File tree

7 files changed

+20
-40
lines changed

7 files changed

+20
-40
lines changed

BencodeNET/IO/BencodeStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public BencodeStream(Stream stream, bool leaveOpen = false)
7575
/// </summary>
7676
public long Position
7777
{
78-
get { return InnerStream.Position; }
78+
get => InnerStream.Position;
7979
set
8080
{
8181
_hasPeeked = false;

BencodeNET/Objects/BString.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public class BString : BObject<IReadOnlyList<byte>>, IComparable<BString>
3939
/// <exception cref="ArgumentNullException"></exception>
4040
public Encoding Encoding
4141
{
42-
get { return _encoding; }
43-
set { _encoding = value ?? DefaultEncoding; }
42+
get => _encoding;
43+
set => _encoding = value ?? DefaultEncoding;
4444
}
4545
private Encoding _encoding;
4646

@@ -111,8 +111,7 @@ public static implicit operator BString(string value)
111111

112112
public override bool Equals(object other)
113113
{
114-
var bstring = other as BString;
115-
if (bstring != null)
114+
if (other is BString bstring)
116115
return Value.SequenceEqual(bstring.Value);
117116

118117
return false;

BencodeNET/Parsing/BObjectParserList.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void AddOrReplace(Type type, IBObjectParser parser)
6060

6161
if (Parsers.ContainsKey(type))
6262
Parsers.Remove(type);
63+
6364
Parsers.Add(type, parser);
6465
}
6566

@@ -105,8 +106,8 @@ public IBObjectParser Get(Type type)
105106
/// <returns>The parser for the specified type or null if there isn't one.</returns>
106107
public IBObjectParser this[Type type]
107108
{
108-
get { return Get(type); }
109-
set { AddOrReplace(type, value); }
109+
get => Get(type);
110+
set => AddOrReplace(type, value);
110111
}
111112

112113
/// <summary>

BencodeNET/Parsing/TorrentParser.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected virtual SingleFileInfo ParseSingleFileInfo(BDictionary info, Encoding
185185
if (!info.ContainsKey(TorrentInfoFields.Length))
186186
return null;
187187

188-
return new SingleFileInfo
188+
return new SingleFileInfo
189189
{
190190
FileName = info.Get<BString>(TorrentInfoFields.Name)?.ToString(encoding),
191191
FileSize = info.Get<BNumber>(TorrentInfoFields.Length),
@@ -278,22 +278,14 @@ private BDictionary ParseExtraInfoFields(BDictionary info)
278278
// TODO: Unit tests
279279
private void FixEncoding(IBObject bobject, Encoding encoding)
280280
{
281-
var dictionary = bobject as BDictionary;
282-
if (dictionary != null)
281+
switch (bobject)
283282
{
284-
FixEncodingInDictionary(dictionary, encoding);
285-
}
286-
287-
var list = bobject as BList;
288-
if (list != null)
289-
{
290-
FixEncodingInList(list, encoding);
291-
}
292-
293-
var value = bobject as BString;
294-
if (value != null)
295-
{
296-
value.Encoding = encoding;
283+
case BDictionary dictionary:
284+
FixEncodingInDictionary(dictionary, encoding); break;
285+
case BList list:
286+
FixEncodingInList(list, encoding); break;
287+
case BString str:
288+
str.Encoding = encoding; break;
297289
}
298290
}
299291

BencodeNET/Torrents/MultiFileInfo.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ public class MultiFileInfo
4141
/// </summary>
4242
public string FullPath
4343
{
44-
get
45-
{
46-
return string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path);
47-
}
48-
set
49-
{
50-
Path = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
51-
}
44+
get => string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), Path);
45+
set => Path = value.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
5246
}
5347
}
5448
}

BencodeNET/Torrents/Torrent.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ public virtual string DisplayName
169169
/// </summary>
170170
public virtual string PiecesAsHexString
171171
{
172-
get
173-
{
174-
return BitConverter.ToString(Pieces).Replace("-", "");
175-
}
172+
get => BitConverter.ToString(Pieces).Replace("-", "");
176173
set
177174
{
178175
if (value?.Length % 40 != 0)

BencodeNET/UtilityExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal static class UtilityExtensions
1414
{
1515
public static bool IsDigit(this char c)
1616
{
17-
return (c >= '0' && c <= '9');
17+
return c >= '0' && c <= '9';
1818
}
1919

2020
public static MemoryStream AsStream(this string str, Encoding encoding)
@@ -24,10 +24,7 @@ public static MemoryStream AsStream(this string str, Encoding encoding)
2424

2525
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
2626
{
27-
TValue value;
28-
if (dictionary.TryGetValue(key, out value))
29-
return value;
30-
return default(TValue);
27+
return dictionary.TryGetValue(key, out TValue value) ? value : default(TValue);
3128
}
3229

3330
public static void Write(this Stream stream, char c)

0 commit comments

Comments
 (0)