Skip to content

Commit f6a633e

Browse files
authored
Use auto properties where possible (#652)
+semver:patch
1 parent 27c4785 commit f6a633e

32 files changed

+173
-408
lines changed

src/FluentNHibernate/Cfg/FluentConfiguration.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class FluentConfiguration
2323
const string DefaultProxyFactoryFactoryClassName = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";
2424
const string CurrentSessionContextClassKey = NHibEnvironment.CurrentSessionContextClass;
2525

26-
readonly Configuration cfg;
2726
readonly IList<Action<Configuration>> configAlterations = new List<Action<Configuration>>();
2827
readonly IDiagnosticMessageDispatcher dispatcher = new DefaultDiagnosticMessageDispatcher();
2928
readonly List<Action<MappingConfiguration>> mappingsBuilders = new List<Action<MappingConfiguration>>();
@@ -40,17 +39,14 @@ internal FluentConfiguration()
4039

4140
internal FluentConfiguration(Configuration cfg)
4241
{
43-
this.cfg = cfg;
42+
this.Configuration = cfg;
4443

4544
#if NH21
4645
this.ProxyFactoryFactory(DefaultProxyFactoryFactoryClassName);
4746
#endif
4847
}
4948

50-
internal Configuration Configuration
51-
{
52-
get { return cfg; }
53-
}
49+
internal Configuration Configuration { get; }
5450

5551
/// <summary>
5652
/// Configure diagnostic logging

src/FluentNHibernate/Conventions/DefaultConventionFinder.cs

+10-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace FluentNHibernate.Conventions;
1212
public class DefaultConventionFinder : IConventionFinder
1313
{
1414
IDiagnosticLogger log = new NullDiagnosticsLogger();
15-
readonly ConventionsCollection conventions = new ConventionsCollection();
1615

1716
/// <summary>
1817
/// Find any conventions implementing T.
@@ -21,9 +20,9 @@ public class DefaultConventionFinder : IConventionFinder
2120
/// <returns>IEnumerable of T</returns>
2221
public IEnumerable<T> Find<T>() where T : IConvention
2322
{
24-
foreach (var type in conventions.Where(x => typeof(T).IsAssignableFrom(x)))
23+
foreach (var type in Conventions.Where(x => typeof(T).IsAssignableFrom(x)))
2524
{
26-
foreach (var instance in conventions[type])
25+
foreach (var instance in Conventions[type])
2726
{
2827
yield return (T)instance;
2928
}
@@ -37,13 +36,10 @@ public void SetLogger(IDiagnosticLogger logger)
3736

3837
public void Merge(IConventionFinder conventionFinder)
3938
{
40-
conventions.Merge(conventionFinder.Conventions);
39+
Conventions.Merge(conventionFinder.Conventions);
4140
}
4241

43-
public ConventionsCollection Conventions
44-
{
45-
get { return conventions; }
46-
}
42+
public ConventionsCollection Conventions { get; } = new ConventionsCollection();
4743

4844
public void AddSource(ITypeSource source)
4945
{
@@ -106,9 +102,9 @@ public void Add(Type type)
106102

107103
public void Add(Type type, object instance)
108104
{
109-
if (conventions.Contains(type) && !AllowMultiplesOf(type)) return;
105+
if (Conventions.Contains(type) && !AllowMultiplesOf(type)) return;
110106

111-
conventions.Add(type, instance);
107+
Conventions.Add(type, instance);
112108
}
113109

114110
/// <summary>
@@ -121,9 +117,9 @@ public void Add(Type type, object instance)
121117
/// <param name="instance">Instance of convention</param>
122118
public void Add<T>(T instance) where T : IConvention
123119
{
124-
if (conventions.Contains(typeof(T)) && !AllowMultiplesOf(instance.GetType())) return;
120+
if (Conventions.Contains(typeof(T)) && !AllowMultiplesOf(instance.GetType())) return;
125121

126-
conventions.Add(typeof(T), instance);
122+
Conventions.Add(typeof(T), instance);
127123
}
128124

129125
private void Add(Type type, MissingConstructor missingConstructor)
@@ -133,9 +129,9 @@ private void Add(Type type, MissingConstructor missingConstructor)
133129
if (missingConstructor == MissingConstructor.Ignore && !HasValidConstructor(type))
134130
return;
135131

136-
if (conventions.Contains(type) && !AllowMultiplesOf(type)) return;
132+
if (Conventions.Contains(type) && !AllowMultiplesOf(type)) return;
137133

138-
conventions.Add(type, Instantiate(type));
134+
Conventions.Add(type, Instantiate(type));
139135
log.ConventionDiscovered(type);
140136
}
141137

src/FluentNHibernate/DummyMethodInfo.cs

+4-13
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ namespace FluentNHibernate;
66

77
internal sealed class DummyMethodInfo : MethodInfo
88
{
9-
private readonly string name;
10-
private readonly Type type;
11-
129
public DummyMethodInfo(string name, Type type)
1310
{
14-
this.name = name;
15-
this.type = type;
11+
this.Name = name;
12+
this.ReturnType = type;
1613
}
1714

18-
public override Type ReturnType
19-
{
20-
get { return type; }
21-
}
15+
public override Type ReturnType { get; }
2216

2317
public override object[] GetCustomAttributes(bool inherit)
2418
{
@@ -55,10 +49,7 @@ public override ICustomAttributeProvider ReturnTypeCustomAttributes
5549
get { return null; }
5650
}
5751

58-
public override string Name
59-
{
60-
get { return name; }
61-
}
52+
public override string Name { get; }
6253

6354
public override Type DeclaringType
6455
{

src/FluentNHibernate/DummyPropertyInfo.cs

+6-15
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ namespace FluentNHibernate;
77
[Serializable]
88
public sealed class DummyPropertyInfo : PropertyInfo
99
{
10-
private readonly string name;
11-
private readonly Type type;
12-
1310
public DummyPropertyInfo(string name, Type type)
1411
{
1512
if (name is null) throw new ArgumentNullException("name");
1613
if (type is null) throw new ArgumentNullException("type");
1714

18-
this.name = name;
19-
this.type = type;
15+
this.Name = name;
16+
this.DeclaringType = type;
2017
}
2118

2219
public override Module Module
@@ -26,7 +23,7 @@ public override Module Module
2623

2724
public override int MetadataToken
2825
{
29-
get { return name.GetHashCode(); }
26+
get { return Name.GetHashCode(); }
3027
}
3128

3229
public override object[] GetCustomAttributes(bool inherit)
@@ -67,15 +64,9 @@ public override ParameterInfo[] GetIndexParameters()
6764
return Array.Empty<ParameterInfo>();
6865
}
6966

70-
public override string Name
71-
{
72-
get { return name; }
73-
}
67+
public override string Name { get; }
7468

75-
public override Type DeclaringType
76-
{
77-
get { return type; }
78-
}
69+
public override Type DeclaringType { get; }
7970

8071
public override Type ReflectedType
8172
{
@@ -84,7 +75,7 @@ public override Type ReflectedType
8475

8576
public override Type PropertyType
8677
{
87-
get { return type; }
78+
get { return DeclaringType; }
8879
}
8980

9081
public override PropertyAttributes Attributes

src/FluentNHibernate/Mapping/AnyPart.cs

+4-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class AnyPart<T> : IAnyMappingProvider
1818
private readonly AttributeStore attributes = new AttributeStore();
1919
private readonly Type entity;
2020
private readonly Member member;
21-
private readonly AccessStrategyBuilder<AnyPart<T>> access;
22-
private readonly CascadeExpression<AnyPart<T>> cascade;
2321
private readonly IList<string> typeColumns = new List<string>();
2422
private readonly IList<string> identifierColumns = new List<string>();
2523
private readonly IList<MetaValueMapping> metaValues = new List<MetaValueMapping>();
@@ -30,8 +28,8 @@ public AnyPart(Type entity, Member member)
3028
{
3129
this.entity = entity;
3230
this.member = member;
33-
access = new AccessStrategyBuilder<AnyPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
34-
cascade = new CascadeExpression<AnyPart<T>>(this, value =>
31+
Access = new AccessStrategyBuilder<AnyPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
32+
Cascade = new CascadeExpression<AnyPart<T>>(this, value =>
3533
{
3634
var current = attributes.Get("Cascade") as string;
3735
attributes.Set("Cascade", Layer.UserSupplied, current is null ? value : string.Format("{0},{1}", current, value));
@@ -53,18 +51,12 @@ void SetDefaultAccess()
5351
/// <summary>
5452
/// Defines how NHibernate will access the object for persisting/hydrating (Defaults to Property)
5553
/// </summary>
56-
public AccessStrategyBuilder<AnyPart<T>> Access
57-
{
58-
get { return access; }
59-
}
54+
public AccessStrategyBuilder<AnyPart<T>> Access { get; }
6055

6156
/// <summary>
6257
/// Cascade style (Defaults to none)
6358
/// </summary>
64-
public CascadeExpression<AnyPart<T>> Cascade
65-
{
66-
get { return cascade; }
67-
}
59+
public CascadeExpression<AnyPart<T>> Cascade { get; }
6860

6961
public AnyPart<T> IdentityType(Expression<Func<T, object>> expression)
7062
{

src/FluentNHibernate/Mapping/ClassMap.cs

+8-25
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ public class ClassMap<T> : ClasslikeMapBase<T>, IMappingProvider
3030
{
3131
protected readonly AttributeStore attributes;
3232
readonly MappingProviderStore providers;
33-
readonly OptimisticLockBuilder<ClassMap<T>> optimisticLock;
3433

3534
readonly IList<ImportPart> imports = new List<ImportPart>();
3635
bool nextBool = true;
3736

38-
readonly HibernateMappingPart hibernateMappingPart = new HibernateMappingPart();
39-
readonly PolymorphismBuilder<ClassMap<T>> polymorphism;
40-
readonly SchemaActionBuilder<ClassMap<T>> schemaAction;
41-
4237
public ClassMap()
4338
: this(new AttributeStore(), new MappingProviderStore())
4439
{}
@@ -48,9 +43,9 @@ protected ClassMap(AttributeStore attributes, MappingProviderStore providers)
4843
{
4944
this.attributes = attributes;
5045
this.providers = providers;
51-
optimisticLock = new OptimisticLockBuilder<ClassMap<T>>(this, value => attributes.Set("OptimisticLock", Layer.UserSupplied, value));
52-
polymorphism = new PolymorphismBuilder<ClassMap<T>>(this, value => attributes.Set("Polymorphism", Layer.UserSupplied, value));
53-
schemaAction = new SchemaActionBuilder<ClassMap<T>>(this, value => attributes.Set("SchemaAction", Layer.UserSupplied, value));
46+
OptimisticLock = new OptimisticLockBuilder<ClassMap<T>>(this, value => attributes.Set("OptimisticLock", Layer.UserSupplied, value));
47+
Polymorphism = new PolymorphismBuilder<ClassMap<T>>(this, value => attributes.Set("Polymorphism", Layer.UserSupplied, value));
48+
SchemaAction = new SchemaActionBuilder<ClassMap<T>>(this, value => attributes.Set("SchemaAction", Layer.UserSupplied, value));
5449
Cache = new CachePart(typeof(T));
5550
}
5651

@@ -69,10 +64,7 @@ protected ClassMap(AttributeStore attributes, MappingProviderStore providers)
6964
/// <example>
7065
/// HibernateMapping.Schema("dto");
7166
/// </example>
72-
public HibernateMappingPart HibernateMapping
73-
{
74-
get { return hibernateMappingPart; }
75-
}
67+
public HibernateMappingPart HibernateMapping { get; } = new HibernateMappingPart();
7668

7769
#region Ids
7870

@@ -427,26 +419,17 @@ public ClassMap<T> BatchSize(int size)
427419
/// <summary>
428420
/// Sets the optimistic locking strategy
429421
/// </summary>
430-
public OptimisticLockBuilder<ClassMap<T>> OptimisticLock
431-
{
432-
get { return optimisticLock; }
433-
}
422+
public OptimisticLockBuilder<ClassMap<T>> OptimisticLock { get; }
434423

435424
/// <summary>
436425
/// Sets the polymorphism behaviour
437426
/// </summary>
438-
public PolymorphismBuilder<ClassMap<T>> Polymorphism
439-
{
440-
get { return polymorphism; }
441-
}
427+
public PolymorphismBuilder<ClassMap<T>> Polymorphism { get; }
442428

443429
/// <summary>
444430
/// Sets the schema action behaviour
445431
/// </summary>
446-
public SchemaActionBuilder<ClassMap<T>> SchemaAction
447-
{
448-
get { return schemaAction; }
449-
}
432+
public SchemaActionBuilder<ClassMap<T>> SchemaAction { get; }
450433

451434
/// <summary>
452435
/// Specifies a check constraint
@@ -689,7 +672,7 @@ ClassMapping IMappingProvider.GetClassMapping()
689672

690673
HibernateMapping IMappingProvider.GetHibernateMapping()
691674
{
692-
var hibernateMapping = ((IHibernateMappingProvider)hibernateMappingPart).GetHibernateMapping();
675+
var hibernateMapping = ((IHibernateMappingProvider)HibernateMapping).GetHibernateMapping();
693676

694677
foreach (var import in imports)
695678
hibernateMapping.AddImport(import.GetImportMapping());

src/FluentNHibernate/Mapping/ComponentPartBase.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public abstract class ComponentPartBase<TEntity, TBuilder> : ClasslikeMapBase<TE
1212
{
1313
protected readonly Member member;
1414
readonly MappingProviderStore providers;
15-
readonly AccessStrategyBuilder<TBuilder> access;
1615
readonly AttributeStore attributes;
1716
protected bool nextBool = true;
1817

@@ -24,7 +23,7 @@ protected ComponentPartBase(AttributeStore attributes, Member member, MappingPro
2423
: base(providers)
2524
{
2625
this.attributes = attributes;
27-
access = new AccessStrategyBuilder<TBuilder>((TBuilder)this, value => attributes.Set("Access", Layer.UserSupplied, value));
26+
Access = new AccessStrategyBuilder<TBuilder>((TBuilder)this, value => attributes.Set("Access", Layer.UserSupplied, value));
2827
this.member = member;
2928
this.providers = providers;
3029

@@ -45,10 +44,7 @@ void SetDefaultAccess()
4544
/// <summary>
4645
/// Set the access and naming strategy for this component.
4746
/// </summary>
48-
public AccessStrategyBuilder<TBuilder> Access
49-
{
50-
get { return access; }
51-
}
47+
public AccessStrategyBuilder<TBuilder> Access { get; }
5248

5349
/// <summary>
5450
/// Specify a parent reference for this component

src/FluentNHibernate/Mapping/CompositeIdentityPart.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ namespace FluentNHibernate.Mapping;
1414
public class CompositeIdentityPart<T> : ICompositeIdMappingProvider
1515
{
1616
readonly Action<Member> onMemberMapped;
17-
readonly AccessStrategyBuilder<CompositeIdentityPart<T>> access;
1817
readonly AttributeStore attributes = new AttributeStore();
1918
readonly IList<ICompositeIdKeyMapping> keys = new List<ICompositeIdKeyMapping>();
2019
bool nextBool = true;
2120

2221
public CompositeIdentityPart(Action<Member> onMemberMapped)
2322
{
2423
this.onMemberMapped = onMemberMapped;
25-
access = new AccessStrategyBuilder<CompositeIdentityPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
24+
Access = new AccessStrategyBuilder<CompositeIdentityPart<T>>(this, value => attributes.Set("Access", Layer.UserSupplied, value));
2625
}
2726

2827
public CompositeIdentityPart(string name, Action<Member> onMemberMapped)
@@ -179,10 +178,7 @@ public virtual CompositeIdentityPart<T> CustomType<CType>()
179178
/// <summary>
180179
/// Set the access and naming strategy for this identity.
181180
/// </summary>
182-
public AccessStrategyBuilder<CompositeIdentityPart<T>> Access
183-
{
184-
get { return access; }
185-
}
181+
public AccessStrategyBuilder<CompositeIdentityPart<T>> Access { get; }
186182

187183
/// <summary>
188184
/// Invert the next boolean operation

src/FluentNHibernate/Mapping/ElementPart.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ public class ElementPart : IElementMappingProvider
1111
readonly Type entity;
1212
readonly AttributeStore attributes = new AttributeStore();
1313
readonly AttributeStore columnAttributes = new AttributeStore();
14-
readonly ColumnMappingCollection<ElementPart> columns;
1514
bool nextBool = true;
1615

1716
public ElementPart(Type entity)
1817
{
1918
this.entity = entity;
20-
columns = new ColumnMappingCollection<ElementPart>(this);
19+
Columns = new ColumnMappingCollection<ElementPart>(this);
2120
}
2221

2322
/// <summary>
@@ -33,10 +32,7 @@ public ElementPart Column(string elementColumnName)
3332
/// <summary>
3433
/// Modify the columns for this element
3534
/// </summary>
36-
public ColumnMappingCollection<ElementPart> Columns
37-
{
38-
get { return columns; }
39-
}
35+
public ColumnMappingCollection<ElementPart> Columns { get; }
4036

4137
/// <summary>
4238
/// Specify the element type

0 commit comments

Comments
 (0)