Skip to content

Commit 366ab36

Browse files
authored
Use C#12 primary constructors (#659)
+semver:patch
1 parent 550b06c commit 366ab36

File tree

246 files changed

+520
-1977
lines changed

Some content is hidden

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

246 files changed

+520
-1977
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ indent_size = 2
1010
indent_style = space
1111
indent_size = 4
1212
insert_final_newline = true
13+
max_line_length = off
1314

1415
csharp_style_namespace_declarations = file_scoped
1516

src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,31 @@ public static XmlElementTester Element(this XmlDocument doc, string path)
3636
return new XmlElementTester(doc, path);
3737
}
3838

39-
public class XmlElementTester
39+
public class XmlElementTester(XmlDocument doc, string path)
4040
{
41-
readonly XmlDocument doc;
42-
string currentPath;
43-
XmlElement currentElement;
44-
45-
public XmlElementTester(XmlDocument doc, string path)
46-
{
47-
currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path);
48-
this.doc = doc;
49-
currentPath = path;
50-
}
41+
readonly XmlDocument doc = doc;
42+
XmlElement currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path);
5143

5244
public XmlElementTester ShouldExist()
5345
{
5446
if (currentElement is null)
55-
throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath));
47+
throw new SpecificationException(string.Format("Should exist at {0} but does not.", path));
5648

5749
return this;
5850
}
5951

6052
public XmlElementTester ShouldNotExist()
6153
{
6254
if (currentElement is not null)
63-
throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath));
55+
throw new SpecificationException(string.Format("Should not exist at {0} but does.", path));
6456

6557
return this;
6658
}
6759

6860
public XmlElementTester HasAttribute(string name)
6961
{
7062
if (!currentElement.HasAttribute(name))
71-
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, currentPath));
63+
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, path));
7264

7365
return this;
7466
}
@@ -81,7 +73,7 @@ public XmlElementTester HasAttribute(string name, string value)
8173
var actual = currentElement.GetAttribute(name);
8274

8375
if (!actual.Equals(value))
84-
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, currentPath, value, actual));
76+
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, path, value, actual));
8577

8678
return this;
8779
}
@@ -94,7 +86,7 @@ public XmlElementTester HasAttribute(string name, Func<string, bool> predicate)
9486
var actual = currentElement.GetAttribute(name);
9587

9688
if (!predicate(actual))
97-
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, currentPath));
89+
throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, path));
9890

9991
return this;
10092
}
@@ -104,7 +96,7 @@ public XmlElementTester DoesntHaveAttribute(string name)
10496
ShouldExist();
10597

10698
if (currentElement.HasAttribute(name))
107-
throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath));
99+
throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, path));
108100

109101
return this;
110102
}

src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44

55
namespace FluentNHibernate.Specs.Automapping.Fixtures;
66

7-
internal class StubTypeSource : ITypeSource
7+
internal class StubTypeSource(params Type[] types) : ITypeSource
88
{
9-
private readonly IEnumerable<Type> types;
10-
11-
public StubTypeSource(params Type[] types)
12-
{
13-
this.types = types;
14-
}
15-
169
public IEnumerable<Type> GetTypes()
1710
{
1811
return types;

src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,8 @@ class ConventionA : IConvention {}
385385
class ConventionB : IConvention {}
386386
class NotAConvention {}
387387

388-
class StubListener : IDiagnosticListener
388+
class StubListener(Action<DiagnosticResults> receiver) : IDiagnosticListener
389389
{
390-
readonly Action<DiagnosticResults> receiver;
391-
392-
public StubListener(Action<DiagnosticResults> receiver)
393-
{
394-
this.receiver = receiver;
395-
}
396-
397390
public void Receive(DiagnosticResults results)
398391
{
399392
receiver(results);

src/FluentNHibernate.Testing/DomainModel/Music.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ public class Album
3737
public int ID { get; set; }
3838
public string Title { get; set;}
3939
public Artist Artist { get; set; }
40-
public ISet<Track> Tracks { get; set; }
41-
public ISet<Tag> Tags { get; set; }
42-
43-
public Album()
44-
{
45-
Tracks = new HashSet<Track>();
46-
Tags = new HashSet<Tag>();
47-
}
40+
public ISet<Track> Tracks { get; set; } = new HashSet<Track>();
41+
public ISet<Tag> Tags { get; set; } = new HashSet<Tag>();
4842
}
4943

5044
public class Track

src/FluentNHibernate.Testing/FluentInterfaceTests/ModelTester.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22

33
namespace FluentNHibernate.Testing.FluentInterfaceTests;
44

5-
public class ModelTester<TFluentClass, TModel>
5+
public class ModelTester<TFluentClass, TModel>(Func<TFluentClass> instantiatePart, Func<TFluentClass, TModel> getModel)
66
{
7-
private readonly Func<TFluentClass> instantiatePart;
8-
private readonly Func<TFluentClass, TModel> getModel;
97
private TFluentClass fluentClass;
108

11-
public ModelTester(Func<TFluentClass> instantiatePart, Func<TFluentClass, TModel> getModel)
12-
{
13-
this.instantiatePart = instantiatePart;
14-
this.getModel = getModel;
15-
}
16-
179
public ModelTester<TFluentClass, TModel> Mapping(Action<TFluentClass> action)
1810
{
1911
fluentClass = instantiatePart();

src/FluentNHibernate.Testing/Testing/PersistenceSpecificationTester.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ public class Cat
1616
public long Id { get; set; }
1717
public string Name { get; set; }
1818
public Kitten FirstKitten { get; set; }
19-
public IList<Kitten> AllKittens { get; set; }
19+
public IList<Kitten> AllKittens { get; set; } = new List<Kitten>();
2020
public Bitmap Picture { get; set; }
2121

22-
public Cat()
23-
{
24-
AllKittens = new List<Kitten>();
25-
}
26-
2722
public IEnumerable<Kitten> EnumerableOfKittens => AllKittens;
2823

2924
public void AddKitten(Kitten kitten)

src/FluentNHibernate.Testing/Testing/Values/Entities.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,20 @@ namespace FluentNHibernate.Testing.Testing.Values;
66

77
public class ListEntity
88
{
9-
private readonly IList<string> backingField;
9+
private readonly IList<string> backingField = new List<string>();
1010

11-
public ListEntity()
12-
{
13-
backingField = new List<string>();
14-
GetterAndSetter = new List<string>();
15-
GetterAndPrivateSetter = new List<string>();
16-
17-
TypedSet = new HashSet<string>();
18-
//Set = new HashedSet();
19-
Collection = new StringCollection();
20-
List = new List<string>();
21-
}
11+
//Set = new HashedSet();
2212

23-
public IEnumerable<string> GetterAndSetter { get; set; }
24-
public IEnumerable<string> GetterAndPrivateSetter { get; private set; }
13+
public IEnumerable<string> GetterAndSetter { get; set; } = new List<string>();
14+
public IEnumerable<string> GetterAndPrivateSetter { get; private set; } = new List<string>();
2515
public IEnumerable<string> BackingField => backingField;
2616

27-
public ISet<string> TypedSet { get; set; }
17+
public ISet<string> TypedSet { get; set; } = new HashSet<string>();
18+
2819
//public ISet Set { get; set; }
29-
public ICollection Collection { get; set; }
20+
public ICollection Collection { get; set; } = new StringCollection();
3021
public string[] Array { get; set; }
31-
public IList<string> List { get; set; }
22+
public IList<string> List { get; set; } = new List<string>();
3223

3324
public void AddListItem(string value)
3425
{
@@ -38,13 +29,8 @@ public void AddListItem(string value)
3829

3930
public class ReferenceEntity
4031
{
41-
public ReferenceEntity()
42-
{
43-
ReferenceList = new List<OtherEntity>();
44-
}
45-
4632
public OtherEntity Reference { get; set; }
47-
public IEnumerable<OtherEntity> ReferenceList { get; set; }
33+
public IEnumerable<OtherEntity> ReferenceList { get; set; } = new List<OtherEntity>();
4834

4935
public void SetReference(OtherEntity value)
5036
{

src/FluentNHibernate.Testing/Testing/XmlWriterTestHelper.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ namespace FluentNHibernate.Testing.Testing;
1414
public class XmlWriterTestHelper<TMappingType>
1515
where TMappingType : IMapping
1616
{
17-
readonly IList<XmlTest> tests;
17+
readonly IList<XmlTest> tests = new List<XmlTest>();
1818
Func<TMappingType> constructor;
1919

20-
public XmlWriterTestHelper()
21-
{
22-
tests = new List<XmlTest>();
23-
}
24-
2520
public XmlTest Check(Expression<Func<TMappingType, object>> sourceProperty, object value)
2621
{
2722
var test = new XmlTest(sourceProperty, value);
@@ -54,20 +49,11 @@ public void VerifyAll(IXmlWriter<TMappingType> writer)
5449
}
5550
}
5651

57-
public class XmlTest
52+
public class XmlTest(Expression<Func<TMappingType, object>> sourceProperty, object value)
5853
{
59-
readonly IDictionary<string, object> checks;
60-
readonly Accessor sourceProperty;
61-
readonly object sourceValue;
62-
readonly Member member;
63-
64-
public XmlTest(Expression<Func<TMappingType, object>> sourceProperty, object value)
65-
{
66-
checks = new Dictionary<string, object>();
67-
member = sourceProperty.ToMember();
68-
this.sourceProperty = ReflectionHelper.GetAccessor(sourceProperty);
69-
sourceValue = value;
70-
}
54+
readonly IDictionary<string, object> checks = new Dictionary<string, object>();
55+
readonly Accessor sourceProperty = ReflectionHelper.GetAccessor(sourceProperty);
56+
readonly Member member = sourceProperty.ToMember();
7157

7258
public XmlTest MapsToAttribute(string attributeName, object value)
7359
{
@@ -77,13 +63,13 @@ public XmlTest MapsToAttribute(string attributeName, object value)
7763

7864
public XmlTest MapsToAttribute(string attributeName)
7965
{
80-
checks[attributeName] = sourceValue;
66+
checks[attributeName] = value;
8167
return this;
8268
}
8369

8470
internal void ApplyToSource(TMappingType mapping)
8571
{
86-
mapping.Set(member.Name, Layer.Defaults, sourceValue);
72+
mapping.Set(member.Name, Layer.Defaults, value);
8773
}
8874

8975
internal void Check(XmlDocument document)
@@ -99,7 +85,7 @@ internal void Check(XmlDocument document)
9985
document.OutputXmlToConsole();
10086

10187
Assert.That(areEqual,
102-
$"Property '{sourceProperty.InnerMember.MemberInfo.ReflectedType?.Name}.{sourceProperty.Name}' was set to '{sourceValue}' " +
88+
$"Property '{sourceProperty.InnerMember.MemberInfo.ReflectedType?.Name}.{sourceProperty.Name}' was set to '{value}' " +
10389
$"and was expected to be written to attribute '{check.Key}' with value '{check.Value}'. " +
10490
$"The value was instead '{attributeValue}'");
10591
//string.Equals()

src/FluentNHibernate.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{83F176
88
FluentKey.snk = FluentKey.snk
99
..\global.json = ..\global.json
1010
..\appveyor.yml = ..\appveyor.yml
11+
..\.editorconfig = ..\.editorconfig
1112
EndProjectSection
1213
EndProject
1314
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{3D285AE0-E5CF-4923-B543-0D70E5C6DE18}"

0 commit comments

Comments
 (0)