Skip to content

Commit ae26935

Browse files
Migrate to net5
1 parent 3895012 commit ae26935

File tree

212 files changed

+1110
-9319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+1110
-9319
lines changed

Adapter/Adapter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Adapter/NoCaching/Demo.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using MoreLinq;
45

56
namespace Adapter.NoCaching
67
{
7-
public class Demo
8+
public static class Demo
89
{
9-
private static readonly List<VectorObject> vectorObjects = new List<VectorObject>
10+
private static readonly List<VectorObject> VectorObjects = new()
1011
{
1112
new VectorRectangle(1, 1, 10, 10),
1213
new VectorRectangle(3, 3, 6, 6)
1314
};
1415

1516
// the interface we have
16-
public static void DrawPoint(Point p)
17+
private static void DrawPoint(Point p)
1718
{
1819
Console.Write(".");
1920
}
2021

21-
private static void Main()
22+
public static void Main()
2223
{
2324
Draw();
2425
Draw();
2526
}
2627

2728
private static void Draw()
2829
{
29-
foreach (var vo in vectorObjects)
30-
foreach (var line in vo)
31-
{
32-
var adapter = new LineToPointAdapter(line);
30+
foreach (var adapter in from vo in VectorObjects from line in vo select new LineToPointAdapter(line))
3331
adapter.ForEach(DrawPoint);
34-
}
3532
}
3633
}
3734
}

Adapter/NoCaching/Line.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
{
33
public class Line
44
{
5-
public Point End;
6-
public Point Start;
7-
8-
public Line()
9-
{
10-
}
5+
public readonly Point End;
6+
public readonly Point Start;
117

128
public Line(Point start, Point end)
139
{

Adapter/NoCaching/LineToPointAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Adapter.NoCaching
55
{
66
public class LineToPointAdapter : Collection<Point>
77
{
8-
private static int count;
8+
private static int _count;
99

1010
public LineToPointAdapter(Line line)
1111
{
1212
Console
1313
.WriteLine(
14-
$"{++count}: Generating points for line [{line.Start.X},{line.Start.Y}]-[{line.End.X},{line.End.Y}] (no caching)");
14+
$"{++_count}: Generating points for line [{line.Start.X},{line.Start.Y}]-[{line.End.X},{line.End.Y}] (no caching)");
1515

1616
var left = Math.Min(line.Start.X, line.End.X);
1717
var right = Math.Max(line.Start.X, line.End.X);

Adapter/WithCaching/Demo.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using MoreLinq;
45

56
namespace Adapter.WithCaching
67
{
7-
public class Demo
8+
public static class Demo
89
{
9-
private static readonly List<VectorObject> vectorObjects = new List<VectorObject>
10+
private static readonly List<VectorObject> VectorObjects = new()
1011
{
1112
new VectorRectangle(1, 1, 10, 10),
1213
new VectorRectangle(3, 3, 6, 6)
1314
};
1415

1516
// the interface we have
16-
public static void DrawPoint(Point p)
17+
private static void DrawPoint(Point p)
1718
{
1819
Console.Write(".");
1920
}
2021

21-
private static void Main(string[] args)
22-
{
23-
Draw();
24-
Draw();
25-
}
22+
// private static void Main(string[] args)
23+
// {
24+
// Draw();
25+
// Draw();
26+
// }
2627

2728
private static void Draw()
2829
{
29-
foreach (var vo in vectorObjects)
30-
foreach (var line in vo)
31-
{
32-
var adapter = new LineToPointAdapter(line);
30+
foreach (var adapter in from vo in VectorObjects from line in vo select new LineToPointAdapter(line))
3331
adapter.ForEach(DrawPoint);
34-
}
3532
}
3633
}
3734
}

Adapter/WithCaching/Line.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
{
33
public class Line
44
{
5-
public Point End;
6-
public Point Start;
5+
public readonly Point End;
6+
public readonly Point Start;
77

88
public Line(Point start, Point end)
99
{
1010
Start = start;
1111
End = end;
1212
}
1313

14-
protected bool Equals(Line other)
14+
private bool Equals(Line other)
1515
{
1616
return Equals(Start, other.Start) && Equals(End, other.End);
1717
}
@@ -20,8 +20,7 @@ public override bool Equals(object obj)
2020
{
2121
if (ReferenceEquals(null, obj)) return false;
2222
if (ReferenceEquals(this, obj)) return true;
23-
if (obj.GetType() != GetType()) return false;
24-
return Equals((Line) obj);
23+
return obj.GetType() == GetType() && Equals((Line) obj);
2524
}
2625

2726
public override int GetHashCode()

Adapter/WithCaching/LineToPointAdapter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace Adapter.WithCaching
66
{
77
public class LineToPointAdapter : IEnumerable<Point>
88
{
9-
private static int count;
10-
private static readonly Dictionary<int, List<Point>> cache = new Dictionary<int, List<Point>>();
9+
private static int _count;
10+
private static readonly Dictionary<int, List<Point>> Cache = new();
1111
private readonly int hash;
1212

1313
public LineToPointAdapter(Line line)
1414
{
1515
hash = line.GetHashCode();
16-
if (cache.ContainsKey(hash)) return; // we already have it
16+
if (Cache.ContainsKey(hash)) return; // we already have it
1717

1818
Console
1919
.WriteLine(
20-
$"{++count}: Generating points for line [{line.Start.X},{line.Start.Y}]-[{line.End.X},{line.End.Y}] (with caching)");
20+
$"{++_count}: Generating points for line [{line.Start.X},{line.Start.Y}]-[{line.End.X},{line.End.Y}] (with caching)");
2121
// ^^^^
2222

2323
var points = new List<Point>();
@@ -36,12 +36,12 @@ public LineToPointAdapter(Line line)
3636
for (var x = left; x <= right; ++x)
3737
points.Add(new Point(x, top));
3838

39-
cache.Add(hash, points);
39+
Cache.Add(hash, points);
4040
}
4141

4242
public IEnumerator<Point> GetEnumerator()
4343
{
44-
return cache[hash].GetEnumerator();
44+
return Cache[hash].GetEnumerator();
4545
}
4646

4747
IEnumerator IEnumerable.GetEnumerator()

Adapter/WithCaching/Point.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
{
33
public class Point
44
{
5-
public int X;
6-
public int Y;
5+
public readonly int X;
6+
public readonly int Y;
77

88
public Point(int x, int y)
99
{
1010
X = x;
1111
Y = y;
1212
}
1313

14-
protected bool Equals(Point other)
14+
private bool Equals(Point other)
1515
{
1616
return X == other.X && Y == other.Y;
1717
}
@@ -20,8 +20,7 @@ public override bool Equals(object obj)
2020
{
2121
if (ReferenceEquals(null, obj)) return false;
2222
if (ReferenceEquals(this, obj)) return true;
23-
if (obj.GetType() != GetType()) return false;
24-
return Equals((Point) obj);
23+
return obj.GetType() == GetType() && Equals((Point) obj);
2524
}
2625

2726
public override int GetHashCode()

Adapter/obj/Adapter.csproj.nuget.cache

Lines changed: 0 additions & 5 deletions
This file was deleted.

Adapter/obj/Adapter.csproj.nuget.dgspec.json

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
{
22
"format": 1,
33
"restore": {
4-
"C:\\Pessoal\\design-patterns\\Adapter\\Adapter.csproj": {}
4+
"/home/jcmdsbr/workspaces/github/aspnetcore-design-patterns/Adapter/Adapter.csproj": {}
55
},
66
"projects": {
7-
"C:\\Pessoal\\design-patterns\\Adapter\\Adapter.csproj": {
7+
"/home/jcmdsbr/workspaces/github/aspnetcore-design-patterns/Adapter/Adapter.csproj": {
88
"version": "1.0.0",
99
"restore": {
10-
"projectUniqueName": "C:\\Pessoal\\design-patterns\\Adapter\\Adapter.csproj",
10+
"projectUniqueName": "/home/jcmdsbr/workspaces/github/aspnetcore-design-patterns/Adapter/Adapter.csproj",
1111
"projectName": "Adapter",
12-
"projectPath": "C:\\Pessoal\\design-patterns\\Adapter\\Adapter.csproj",
13-
"packagesPath": "C:\\Users\\jean.moreira\\.nuget\\packages\\",
14-
"outputPath": "C:\\Pessoal\\design-patterns\\Adapter\\obj\\",
12+
"projectPath": "/home/jcmdsbr/workspaces/github/aspnetcore-design-patterns/Adapter/Adapter.csproj",
13+
"packagesPath": "/home/jcmdsbr/.nuget/packages/",
14+
"outputPath": "/home/jcmdsbr/workspaces/github/aspnetcore-design-patterns/Adapter/obj/",
1515
"projectStyle": "PackageReference",
1616
"fallbackFolders": [
17-
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
17+
"/usr/share/dotnet/sdk/NuGetFallbackFolder"
1818
],
1919
"configFilePaths": [
20-
"C:\\Users\\jean.moreira\\AppData\\Roaming\\NuGet\\NuGet.Config",
21-
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
20+
"/home/jcmdsbr/.nuget/NuGet/NuGet.Config"
2221
],
2322
"originalTargetFrameworks": [
24-
"netcoreapp2.2"
23+
"net5.0"
2524
],
2625
"sources": {
27-
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
2826
"https://api.nuget.org/v3/index.json": {}
2927
},
3028
"frameworks": {
31-
"netcoreapp2.2": {
29+
"net5.0": {
30+
"targetAlias": "net5.0",
3231
"projectReferences": {}
3332
}
3433
},
@@ -39,24 +38,30 @@
3938
}
4039
},
4140
"frameworks": {
42-
"netcoreapp2.2": {
41+
"net5.0": {
42+
"targetAlias": "net5.0",
4343
"dependencies": {
44-
"Microsoft.NETCore.App": {
45-
"suppressParent": "All",
46-
"target": "Package",
47-
"version": "[2.2.0, )",
48-
"autoReferenced": true
49-
},
5044
"morelinq": {
5145
"target": "Package",
5246
"version": "[3.1.1, )"
5347
}
5448
},
5549
"imports": [
56-
"net461"
50+
"net461",
51+
"net462",
52+
"net47",
53+
"net471",
54+
"net472",
55+
"net48"
5756
],
5857
"assetTargetFallback": true,
59-
"warn": true
58+
"warn": true,
59+
"frameworkReferences": {
60+
"Microsoft.NETCore.App": {
61+
"privateAssets": "all"
62+
}
63+
},
64+
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/5.0.201/RuntimeIdentifierGraph.json"
6065
}
6166
}
6267
}

0 commit comments

Comments
 (0)