Skip to content

Commit d1c6e23

Browse files
author
Mahmudul Hasan
authored
Migrated to .NET5 (#160)
1 parent 15e8565 commit d1c6e23

24 files changed

+357
-354
lines changed

FireSharp.Core/AutoRedirectHttpClientHandler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@ namespace FireSharp.Core
88
{
99
internal class AutoRedirectHttpClientHandler : DelegatingHandler
1010
{
11-
private int _maximumAutomaticRedirections;
11+
private int maximumAutomaticRedirections;
1212

1313
public int MaximumAutomaticRedirections
1414
{
15-
get { return _maximumAutomaticRedirections; }
15+
get => maximumAutomaticRedirections;
1616
set
1717
{
1818
if (value < 1)
1919
{
2020
throw new ArgumentException("The specified value must be greater than 0.");
2121
}
2222

23-
_maximumAutomaticRedirections = value;
23+
maximumAutomaticRedirections = value;
2424
}
2525
}
2626

2727
public AutoRedirectHttpClientHandler()
2828
{
29-
var handler = new HttpClientHandler { AllowAutoRedirect = false };
29+
HttpClientHandler handler = new() { AllowAutoRedirect = false };
3030
InnerHandler = handler;
3131
MaximumAutomaticRedirections = handler.MaxAutomaticRedirections;
3232
}
3333

3434
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
3535
{
36-
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
36+
HttpResponseMessage response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
3737

3838
if (!IsRedirect(response))
3939
{
4040
return response;
4141
}
4242

43-
var redirectCount = 0;
43+
int redirectCount = 0;
4444

4545
while (IsRedirect(response))
4646
{

FireSharp.Core/Config/FirebaseConfig.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace FireSharp.Core.Config
55
{
66
public class FirebaseConfig : IFirebaseConfig
77
{
8-
private string _basePath;
8+
private string basePath;
99

1010
public FirebaseConfig()
1111
{
@@ -14,11 +14,8 @@ public FirebaseConfig()
1414

1515
public string BasePath
1616
{
17-
get
18-
{
19-
return _basePath.EndsWith("/") ? _basePath : $"{_basePath}/";
20-
}
21-
set { _basePath = value; }
17+
get => basePath.EndsWith("/") ? basePath : $"{basePath}/";
18+
set => basePath = value;
2219
}
2320

2421
public string Host { get; set; }

FireSharp.Core/EventStreaming/Delegates.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public delegate void ValueAddedEventHandler(object sender, ValueAddedEventArgs args, object context);
44

5-
public delegate void ValueRootAddedEventHandler<T>(object sender, T arg);
5+
public delegate void ValueRootAddedEventHandler<in T>(object sender, T arg);
66

77
public delegate void ValueChangedEventHandler(object sender, ValueChangedEventArgs args, object context);
88

FireSharp.Core/EventStreaming/SimpleCacheItem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace FireSharp.Core.EventStreaming
44
{
55
internal class SimpleCacheItem
66
{
7-
private List<SimpleCacheItem> _children;
7+
private List<SimpleCacheItem> children;
88
public string Name { get; set; }
99
public string Value { get; set; }
1010
public SimpleCacheItem Parent { get; set; }
1111
public bool Created { get; set; }
1212

13-
public List<SimpleCacheItem> Children => _children ?? (_children = new List<SimpleCacheItem>());
13+
public List<SimpleCacheItem> Children => children ??= new List<SimpleCacheItem>();
1414
}
1515
}

FireSharp.Core/EventStreaming/TemporaryCache.cs

+29-27
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace FireSharp.Core.EventStreaming
88
{
99
internal sealed class TemporaryCache : IDisposable
1010
{
11-
private readonly LinkedList<SimpleCacheItem> _pathFromRootList = new LinkedList<SimpleCacheItem>();
12-
private readonly char[] _seperator = {'/'};
13-
private readonly object _treeLock = new object();
11+
private readonly LinkedList<SimpleCacheItem> pathFromRootList = new();
12+
private readonly char[] separator = {'/'};
13+
private readonly object treeLock = new();
1414

1515
public object Context = null;
1616

@@ -27,42 +27,40 @@ public TemporaryCache()
2727
Dispose(false);
2828
}
2929

30-
internal SimpleCacheItem Root { get; } = new SimpleCacheItem();
30+
internal SimpleCacheItem Root { get; } = new();
3131

3232
public void Replace(string path, JsonReader data)
3333
{
34-
lock (_treeLock)
34+
lock (treeLock)
3535
{
36-
var root = FindRoot(path);
36+
SimpleCacheItem root = FindRoot(path);
3737
Replace(root, data);
3838
}
3939
}
4040

4141
public void Update(string path, JsonReader data)
4242
{
43-
lock (_treeLock)
43+
lock (treeLock)
4444
{
45-
var root = FindRoot(path);
45+
SimpleCacheItem root = FindRoot(path);
4646
UpdateChildren(root, data);
4747
}
4848
}
4949

5050
private SimpleCacheItem FindRoot(string path)
5151
{
52-
var segments = path.Split(_seperator, StringSplitOptions.RemoveEmptyEntries);
52+
string[] segments = path.Split(separator, StringSplitOptions.RemoveEmptyEntries);
5353

5454
return segments.Aggregate(Root, GetNamedChild);
5555
}
5656

5757
private static SimpleCacheItem GetNamedChild(SimpleCacheItem root, string segment)
5858
{
59-
var newRoot = root.Children.FirstOrDefault(c => c.Name == segment);
59+
SimpleCacheItem newRoot = root.Children.FirstOrDefault(c => c.Name == segment);
6060

61-
if (newRoot == null)
62-
{
63-
newRoot = new SimpleCacheItem {Name = segment, Parent = root, Created = true};
64-
root.Children.Add(newRoot);
65-
}
61+
if (newRoot != null) return newRoot;
62+
newRoot = new SimpleCacheItem {Name = segment, Parent = root, Created = true};
63+
root.Children.Add(newRoot);
6664

6765
return newRoot;
6866
}
@@ -86,7 +84,7 @@ private void UpdateChildren(SimpleCacheItem root, JsonReader reader, bool replac
8684
switch (reader.TokenType)
8785
{
8886
case JsonToken.PropertyName:
89-
UpdateChildren(GetNamedChild(root, reader.Value.ToString()), reader);
87+
if (reader.Value != null) UpdateChildren(GetNamedChild(root, reader.Value.ToString()), reader);
9088
break;
9189
case JsonToken.Boolean:
9290
case JsonToken.Bytes:
@@ -96,14 +94,18 @@ private void UpdateChildren(SimpleCacheItem root, JsonReader reader, bool replac
9694
case JsonToken.String:
9795
if (root.Created)
9896
{
99-
root.Value = reader.Value.ToString();
100-
OnAdded(new ValueAddedEventArgs(PathFromRoot(root), reader.Value.ToString()));
97+
if (reader.Value != null)
98+
{
99+
root.Value = reader.Value.ToString();
100+
OnAdded(new ValueAddedEventArgs(PathFromRoot(root), reader.Value.ToString()));
101+
}
102+
101103
root.Created = false;
102104
}
103105
else
104106
{
105-
var oldData = root.Value;
106-
root.Value = reader.Value.ToString();
107+
string oldData = root.Value;
108+
if (reader.Value != null) root.Value = reader.Value.ToString();
107109
OnUpdated(new ValueChangedEventArgs(PathFromRoot(root), root.Value, oldData));
108110
}
109111

@@ -127,7 +129,7 @@ private void DeleteChild(SimpleCacheItem root)
127129
}
128130
else
129131
{
130-
foreach (var child in root.Children.ToArray())
132+
foreach (SimpleCacheItem child in root.Children.ToArray())
131133
{
132134
RemoveChildFromParent(child);
133135
OnRemoved(new ValueRemovedEventArgs(PathFromRoot(child)));
@@ -147,27 +149,27 @@ private bool RemoveChildFromParent(SimpleCacheItem child)
147149

148150
private string PathFromRoot(SimpleCacheItem root)
149151
{
150-
var size = 1;
152+
int size = 1;
151153

152154
while (root.Name != null)
153155
{
154156
size += root.Name.Length + 1;
155-
_pathFromRootList.AddFirst(root);
157+
pathFromRootList.AddFirst(root);
156158
root = root.Parent;
157159
}
158160

159-
if (_pathFromRootList.Count == 0)
161+
if (pathFromRootList.Count == 0)
160162
{
161163
return "/";
162164
}
163165

164-
var sb = new StringBuilder(size);
165-
foreach (var d in _pathFromRootList)
166+
StringBuilder sb = new(size);
167+
foreach (SimpleCacheItem d in pathFromRootList)
166168
{
167169
sb.Append($"/{d.Name}");
168170
}
169171

170-
_pathFromRootList.Clear();
172+
pathFromRootList.Clear();
171173

172174
return sb.ToString();
173175
}

FireSharp.Core/FireSharp.Core.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<AssemblyName>FireSharp.Core</AssemblyName>
66
<RootNamespace>FireSharp.Core</RootNamespace>
7-
<Version>2.1.0</Version>
7+
<Version>5.0.0</Version>
88
</PropertyGroup>
99

1010
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
16+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1717
</ItemGroup>
1818

1919
</Project>

0 commit comments

Comments
 (0)