Skip to content

Commit 2b8af17

Browse files
committed
Refactored files to file-scoped namespace
1 parent 23b7f28 commit 2b8af17

File tree

117 files changed

+4036
-4151
lines changed

Some content is hidden

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

117 files changed

+4036
-4151
lines changed

LinkDotNet.Blog.Domain/BlogPost.cs

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,77 @@
22
using System.Collections.Generic;
33
using System.Linq;
44

5-
namespace LinkDotNet.Blog.Domain
5+
namespace LinkDotNet.Blog.Domain;
6+
7+
public class BlogPost : Entity
68
{
7-
public class BlogPost : Entity
9+
private BlogPost()
810
{
9-
private BlogPost()
10-
{
11-
}
11+
}
1212

13-
public string Title { get; private set; }
13+
public string Title { get; private set; }
1414

15-
public string ShortDescription { get; private set; }
15+
public string ShortDescription { get; private set; }
1616

17-
public string Content { get; private set; }
17+
public string Content { get; private set; }
1818

19-
public string PreviewImageUrl { get; private set; }
19+
public string PreviewImageUrl { get; private set; }
2020

21-
public DateTime UpdatedDate { get; private set; }
21+
public DateTime UpdatedDate { get; private set; }
2222

23-
public virtual ICollection<Tag> Tags { get; private set; }
23+
public virtual ICollection<Tag> Tags { get; private set; }
2424

25-
public bool IsPublished { get; set; }
25+
public bool IsPublished { get; set; }
2626

27-
public int Likes { get; set; }
27+
public int Likes { get; set; }
2828

29-
public static BlogPost Create(
30-
string title,
31-
string shortDescription,
32-
string content,
33-
string previewImageUrl,
34-
bool isPublished,
35-
DateTime? updatedDate = null,
36-
IEnumerable<string> tags = null)
29+
public static BlogPost Create(
30+
string title,
31+
string shortDescription,
32+
string content,
33+
string previewImageUrl,
34+
bool isPublished,
35+
DateTime? updatedDate = null,
36+
IEnumerable<string> tags = null)
37+
{
38+
var blogPost = new BlogPost
3739
{
38-
var blogPost = new BlogPost
39-
{
40-
Title = title,
41-
ShortDescription = shortDescription,
42-
Content = content,
43-
UpdatedDate = updatedDate ?? DateTime.Now,
44-
PreviewImageUrl = previewImageUrl,
45-
IsPublished = isPublished,
46-
Tags = tags?.Select(t => new Tag { Content = t.Trim() }).ToList(),
47-
};
40+
Title = title,
41+
ShortDescription = shortDescription,
42+
Content = content,
43+
UpdatedDate = updatedDate ?? DateTime.Now,
44+
PreviewImageUrl = previewImageUrl,
45+
IsPublished = isPublished,
46+
Tags = tags?.Select(t => new Tag { Content = t.Trim() }).ToList(),
47+
};
4848

49-
return blogPost;
50-
}
49+
return blogPost;
50+
}
5151

52-
public void Update(BlogPost from)
52+
public void Update(BlogPost from)
53+
{
54+
Title = from.Title;
55+
ShortDescription = from.ShortDescription;
56+
Content = from.Content;
57+
UpdatedDate = from.UpdatedDate;
58+
PreviewImageUrl = from.PreviewImageUrl;
59+
IsPublished = from.IsPublished;
60+
ReplaceTags(from.Tags);
61+
}
62+
63+
private void ReplaceTags(IEnumerable<Tag> tags)
64+
{
65+
Tags?.Clear();
66+
if (Tags == null || tags == null)
5367
{
54-
Title = from.Title;
55-
ShortDescription = from.ShortDescription;
56-
Content = from.Content;
57-
UpdatedDate = from.UpdatedDate;
58-
PreviewImageUrl = from.PreviewImageUrl;
59-
IsPublished = from.IsPublished;
60-
ReplaceTags(from.Tags);
68+
Tags = tags?.ToList();
6169
}
62-
63-
private void ReplaceTags(IEnumerable<Tag> tags)
70+
else
6471
{
65-
Tags?.Clear();
66-
if (Tags == null || tags == null)
67-
{
68-
Tags = tags?.ToList();
69-
}
70-
else
72+
foreach (var tag in tags)
7173
{
72-
foreach (var tag in tags)
73-
{
74-
Tags.Add(tag);
75-
}
74+
Tags.Add(tag);
7675
}
7776
}
7877
}
79-
}
78+
}

LinkDotNet.Blog.Domain/Entity.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace LinkDotNet.Blog.Domain
1+
namespace LinkDotNet.Blog.Domain;
2+
3+
public abstract class Entity
24
{
3-
public abstract class Entity
4-
{
5-
public string Id { get; set; }
6-
}
7-
}
5+
public string Id { get; set; }
6+
}

LinkDotNet.Blog.Domain/Enumeration.cs

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,83 @@
33
using System.Linq;
44
using System.Reflection;
55

6-
namespace LinkDotNet.Blog.Domain
6+
namespace LinkDotNet.Blog.Domain;
7+
8+
public abstract class Enumeration<TEnumeration>
9+
where TEnumeration : Enumeration<TEnumeration>
710
{
8-
public abstract class Enumeration<TEnumeration>
9-
where TEnumeration : Enumeration<TEnumeration>
11+
protected Enumeration()
1012
{
11-
protected Enumeration()
12-
{
13-
}
13+
}
1414

15-
protected Enumeration(string key)
15+
protected Enumeration(string key)
16+
{
17+
if (string.IsNullOrWhiteSpace(key))
1618
{
17-
if (string.IsNullOrWhiteSpace(key))
18-
{
19-
throw new ArgumentException("The enum key cannot be null or empty");
20-
}
21-
22-
Key = key;
19+
throw new ArgumentException("The enum key cannot be null or empty");
2320
}
2421

25-
public static IReadOnlyCollection<TEnumeration> All => GetEnumerations();
22+
Key = key;
23+
}
2624

27-
public string Key { get; }
25+
public static IReadOnlyCollection<TEnumeration> All => GetEnumerations();
2826

29-
public static bool operator ==(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
30-
{
31-
if (a is null || b is null)
32-
{
33-
return false;
34-
}
27+
public string Key { get; }
3528

36-
return a.Key.Equals(b.Key);
37-
}
38-
39-
public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
29+
public static bool operator ==(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
30+
{
31+
if (a is null || b is null)
4032
{
41-
return !(a == b);
33+
return false;
4234
}
4335

44-
public static TEnumeration Create(string key)
45-
{
46-
var enumeration = All.SingleOrDefault(p => p.Key == key);
36+
return a.Key.Equals(b.Key);
37+
}
4738

48-
if (enumeration is null)
49-
{
50-
throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");
51-
}
39+
public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
40+
{
41+
return !(a == b);
42+
}
5243

53-
return enumeration;
44+
public static TEnumeration Create(string key)
45+
{
46+
var enumeration = All.SingleOrDefault(p => p.Key == key);
47+
48+
if (enumeration is null)
49+
{
50+
throw new InvalidOperationException($"{key} is not a valid value for {typeof(TEnumeration).Name}");
5451
}
5552

56-
public override int GetHashCode() => Key.GetHashCode();
53+
return enumeration;
54+
}
5755

58-
public override bool Equals(object obj)
59-
{
60-
if (obj is null)
61-
{
62-
return false;
63-
}
56+
public override int GetHashCode() => Key.GetHashCode();
6457

65-
if (obj.GetType() != typeof(TEnumeration))
66-
{
67-
return false;
68-
}
58+
public override bool Equals(object obj)
59+
{
60+
if (obj is null)
61+
{
62+
return false;
63+
}
6964

70-
return ((TEnumeration)obj).Key == Key;
65+
if (obj.GetType() != typeof(TEnumeration))
66+
{
67+
return false;
7168
}
7269

73-
public override string ToString() => Key;
70+
return ((TEnumeration)obj).Key == Key;
71+
}
7472

75-
private static TEnumeration[] GetEnumerations()
76-
{
77-
var enumerationType = typeof(TEnumeration);
73+
public override string ToString() => Key;
7874

79-
return enumerationType
80-
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
81-
.Where(info => info.FieldType == typeof(TEnumeration))
82-
.Select(info => (TEnumeration)info.GetValue(null))
83-
.ToArray();
84-
}
75+
private static TEnumeration[] GetEnumerations()
76+
{
77+
var enumerationType = typeof(TEnumeration);
78+
79+
return enumerationType
80+
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
81+
.Where(info => info.FieldType == typeof(TEnumeration))
82+
.Select(info => (TEnumeration)info.GetValue(null))
83+
.ToArray();
8584
}
86-
}
85+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
namespace LinkDotNet.Blog.Domain
1+
namespace LinkDotNet.Blog.Domain;
2+
3+
public class Introduction
24
{
3-
public class Introduction
4-
{
5-
public string BackgroundUrl { get; set; }
5+
public string BackgroundUrl { get; set; }
66

7-
public string ProfilePictureUrl { get; set; }
7+
public string ProfilePictureUrl { get; set; }
88

9-
public string Description { get; set; }
10-
}
11-
}
9+
public string Description { get; set; }
10+
}
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
namespace LinkDotNet.Blog.Domain
1+
namespace LinkDotNet.Blog.Domain;
2+
3+
public class ProficiencyLevel : Enumeration<ProficiencyLevel>
24
{
3-
public class ProficiencyLevel : Enumeration<ProficiencyLevel>
4-
{
5-
public static readonly ProficiencyLevel Familiar = new(nameof(Familiar));
6-
public static readonly ProficiencyLevel Proficient = new(nameof(Proficient));
7-
public static readonly ProficiencyLevel Expert = new(nameof(Expert));
5+
public static readonly ProficiencyLevel Familiar = new(nameof(Familiar));
6+
public static readonly ProficiencyLevel Proficient = new(nameof(Proficient));
7+
public static readonly ProficiencyLevel Expert = new(nameof(Expert));
88

9-
private ProficiencyLevel()
10-
: base()
11-
{
12-
}
9+
private ProficiencyLevel()
10+
: base()
11+
{
12+
}
1313

14-
private ProficiencyLevel(string key)
15-
: base(key)
16-
{
17-
}
14+
private ProficiencyLevel(string key)
15+
: base(key)
16+
{
1817
}
19-
}
18+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
namespace LinkDotNet.Blog.Domain
1+
namespace LinkDotNet.Blog.Domain;
2+
3+
public record ProfileInformation
24
{
3-
public record ProfileInformation
4-
{
5-
public string Name { get; init; }
5+
public string Name { get; init; }
66

7-
public string Heading { get; init; }
7+
public string Heading { get; init; }
88

9-
public string ProfilePictureUrl { get; init; }
10-
}
11-
}
9+
public string ProfilePictureUrl { get; init; }
10+
}

0 commit comments

Comments
 (0)