Skip to content

Commit 20b3f6e

Browse files
committed
More static funcs and actions
1 parent 6fcddc3 commit 20b3f6e

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

Orm/Xtensive.Orm/Orm/Building/Builders/ModelBuilder.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void BuildPrefetchActions()
172172
var domain = context.Domain;
173173
foreach (var type in context.Model.Types.Entities) {
174174
var associations = type.GetOwnerAssociations()
175-
.Where(a => a.OnOwnerRemove is OnRemoveAction.Cascade or OnRemoveAction.Clear);
175+
.Where(static a => a.OnOwnerRemove is OnRemoveAction.Cascade or OnRemoveAction.Clear);
176176
var action = new PrefetchActionContainer(type).BuildPrefetchAction(associations);
177177
if (action != null) {
178178
domain.PrefetchActionMap.Add(type, action);
@@ -200,11 +200,11 @@ private void BuildTypes(IReadOnlyList<TypeDef> typeDefs)
200200

201201
private void PreprocessAssociations()
202202
{
203-
foreach (var typeInfo in context.Model.Types.Where(t => t.IsEntity && !t.IsAuxiliary)) {
203+
foreach (var typeInfo in context.Model.Types.Where(static t => t.IsEntity && !t.IsAuxiliary)) {
204204

205205
// pair integrity escalation and consistency check
206-
typesWithProcessedInheritedAssociations.Add(typeInfo);
207-
var refFields = typeInfo.Fields.Where(f => f.IsEntity || f.IsEntitySet).ToList();
206+
_ = typesWithProcessedInheritedAssociations.Add(typeInfo);
207+
var refFields = typeInfo.Fields.Where(static f => f.IsEntity || f.IsEntitySet).ToList();
208208
// check for interface fields
209209
foreach (var refField in refFields) {
210210
var parentIsPaired = false;
@@ -257,11 +257,16 @@ private void PreprocessAssociations()
257257

258258
var fieldCopy = refField;
259259
if (!parentIsPaired)
260-
context.PairedAssociations.RemoveAll(pa => fieldCopy.Associations.Contains(pa.First));
261-
Func<AssociationInfo, bool> associationFilter = a => context.PairedAssociations
262-
.Any(pa => a.TargetType.UnderlyingType.IsAssignableFrom(pa.First.OwnerType.UnderlyingType)
263-
&& pa.Second == a.OwnerField.Name
264-
&& a.OwnerType == pa.First.TargetType);
260+
_ = context.PairedAssociations.RemoveAll(pa => fieldCopy.Associations.Contains(pa.First));
261+
262+
bool associationFilter(AssociationInfo a)
263+
{
264+
return context.PairedAssociations
265+
.Any(pa => a.TargetType.UnderlyingType.IsAssignableFrom(pa.First.OwnerType.UnderlyingType)
266+
&& pa.Second == a.OwnerField.Name
267+
&& a.OwnerType == pa.First.TargetType);
268+
}
269+
265270
var associationsToKeep = refField.IsInterfaceImplementation
266271
? refField.Associations
267272
.Where(associationFilter)
@@ -479,8 +484,7 @@ private void RegiserReferences(Dictionary<TypeInfo, int> referenceRegistrator, p
479484
foreach (var type in typesToRegisterReferences) {
480485
var typeImplementors = type.DirectImplementors;
481486
var descendantTypes = type.AllDescendants;
482-
if (typeImplementors.Any())
483-
{
487+
if (typeImplementors.Any()) {
484488
foreach (var implementor in typeImplementors)
485489
if (referenceRegistrator.ContainsKey(implementor))
486490
referenceRegistrator[implementor] += 1;
@@ -500,32 +504,32 @@ private void RegiserReferences(Dictionary<TypeInfo, int> referenceRegistrator, p
500504

501505
private void MarkAuxiliaryTypesAsOutboundOnly(IEnumerable<TypeInfo> typesToMark)
502506
{
503-
var auxiliary = typesToMark.Where(el => el.IsAuxiliary);
507+
var auxiliary = typesToMark.Where(static el => el.IsAuxiliary);
504508
foreach (var typeInfo in auxiliary)
505509
typeInfo.IsOutboundOnly = true;
506510
}
507511

508512
private void MarkTypesAsInboundOnly(Dictionary<TypeInfo, int> outputRefCountDictionary)
509513
{
510-
foreach (var output in outputRefCountDictionary.Where(el => el.Value==0))
514+
foreach (var output in outputRefCountDictionary.Where(static el => el.Value == 0))
511515
output.Key.IsInboundOnly = true;
512516
}
513517

514518
private void MarkTypesAsOutboundOnly(Dictionary<TypeInfo, int> inputRefCountDictionary)
515519
{
516-
foreach (var input in inputRefCountDictionary.Where(el => el.Value == 0))
520+
foreach (var input in inputRefCountDictionary.Where(static el => el.Value == 0))
517521
input.Key.IsOutboundOnly = true;
518522
}
519523

520524
private IEnumerable<AssociationInfo> GetMasterOrNonPairedAssociations(IEnumerable<AssociationInfo> allAssociations)
521525
{
522-
return allAssociations.Where(el => el.IsMaster || !el.IsPaired);
526+
return allAssociations.Where(static el => el.IsMaster || !el.IsPaired);
523527
}
524528

525529
private Dictionary<TypeInfo,int> InitReferencesOfTypesDictionary(TypeInfoCollection allTypes)
526530
{
527531
var referencesOfTypeDictionary = new Dictionary<TypeInfo, int>();
528-
var entityTypes = allTypes.Where(el => el.IsEntity && !el.IsInterface && !el.IsStructure && !el.IsSystem && !el.IsAuxiliary);
532+
var entityTypes = allTypes.Where(static el => el.IsEntity && !el.IsInterface && !el.IsStructure && !el.IsSystem && !el.IsAuxiliary);
529533
foreach (var type in entityTypes) {
530534
referencesOfTypeDictionary.Add(type,0);
531535
}
@@ -544,7 +548,7 @@ private static List<Node<Node<TypeDef>, object>> PrepareNodesForTopologicalSort(
544548
var dict = nodes.ToDictionary(o => o.Item);
545549
foreach (var typeNode in typeNodes) {
546550
var tail = dict[typeNode];
547-
foreach (var head in typeNode.OutgoingEdges.Where(static o => o.Weight == EdgeWeight.High).Select(o => o.Head).Distinct()) {
551+
foreach (var head in typeNode.OutgoingEdges.Where(static o => o.Weight == EdgeWeight.High).Select(static o => o.Head).Distinct()) {
548552
if (head != typeNode) {
549553
dict[head].AddConnection(tail, null);
550554
}
@@ -560,7 +564,7 @@ private IEnumerable<TypeDef> GetTypeBuildSequence()
560564
?? throw new DomainBuilderException(string.Format(
561565
Strings.ExAtLeastOneLoopHaveBeenFoundInPersistentTypeDependenciesGraphSuspiciousTypesX,
562566
loops.Select(node => node.Item.Value.Name).ToCommaDelimitedString()));
563-
var dependentTypes = result.Select(n => n.Value).ToList();
567+
var dependentTypes = result.Select(static n => n.Value).ToList();
564568
var independentTypes = context.ModelDef.Types.Except(dependentTypes);
565569
return independentTypes.Concat(dependentTypes);
566570
}

Orm/Xtensive.Orm/Orm/Building/Builders/ModelDefBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void ProcessFullTextIndexes(TypeDef typeDef)
115115
}
116116

117117
var fullTextIndexDef = new FullTextIndexDef(typeDef);
118-
foreach (var fieldDef in typeDef.Fields.Where(f => f.UnderlyingProperty != null)) {
118+
foreach (var fieldDef in typeDef.Fields.Where(static f => f.UnderlyingProperty != null)) {
119119
var fullTextAttribute = fieldDef.UnderlyingProperty
120120
.GetAttribute<FullTextAttribute>(AttributeSearchOptions.InheritAll);
121121
if (fullTextAttribute == null) {
@@ -181,8 +181,8 @@ private void ProcessIndexes(TypeDef typeDef)
181181
{
182182
// process indexes which defined directly for type
183183
var ownIndexesOfType = typeDef.Fields
184-
.Where(f => f.IsIndexed)
185-
.Select(f => new IndexAttribute(f.Name))
184+
.Where(static f => f.IsIndexed)
185+
.Select(static f => new IndexAttribute(f.Name))
186186
.Concat(typeDef.UnderlyingType.GetAttributes<IndexAttribute>(AttributeSearchOptions.InheritNone) ??
187187
Enumerable.Empty<IndexAttribute>());
188188

Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public TypeInfo BuildType(TypeDef typeDef)
5050
MappingName = typeDef.MappingName,
5151
MappingDatabase = typeDef.MappingDatabase,
5252
MappingSchema = typeDef.MappingSchema,
53-
HasVersionRoots = TypeHelper.GetInterfacesUnordered(typeDef.UnderlyingType).Any(static type => type == typeof(IHasVersionRoots)),
53+
HasVersionRoots = TypeHelper.GetInterfacesUnordered(typeDef.UnderlyingType)
54+
.Any(static type => type == typeof(IHasVersionRoots)),
5455
Validators = validators,
5556
};
5657

@@ -63,8 +64,8 @@ public TypeInfo BuildType(TypeDef typeDef)
6364
// Registering connections between type & its ancestors
6465
var node = context.DependencyGraph.TryGetNode(typeDef);
6566
if (node != null) {
66-
foreach (var edge in node.OutgoingEdges.Where(e =>
67-
e.Kind == EdgeKind.Implementation || e.Kind == EdgeKind.Inheritance)) {
67+
foreach (var edge in node.OutgoingEdges.Where(static e =>
68+
e.Kind is EdgeKind.Implementation or EdgeKind.Inheritance)) {
6869
var baseType = context.Model.Types[edge.Head.Value.UnderlyingType];
6970
switch (edge.Kind) {
7071
case EdgeKind.Inheritance:
@@ -92,7 +93,7 @@ public TypeInfo BuildType(TypeDef typeDef)
9293
else {
9394
var root = context.Model.Types[hierarchyDef.Root.UnderlyingType];
9495
typeInfo.Hierarchy = root.Hierarchy;
95-
foreach (var fieldInfo in root.Fields.Where(f => f.IsPrimaryKey && f.Parent == null)) {
96+
foreach (var fieldInfo in root.Fields.Where(static f => f.IsPrimaryKey && f.Parent == null)) {
9697
BuildInheritedField(typeInfo, fieldInfo);
9798
}
9899
}
@@ -112,7 +113,7 @@ public TypeInfo BuildType(TypeDef typeDef)
112113
public void BuildTypeDiscriminatorMap(TypeDef typeDef, TypeInfo typeInfo)
113114
{
114115
if (typeDef.TypeDiscriminatorValue != null) {
115-
var targetField = typeInfo.Fields.SingleOrDefault(f => f.IsTypeDiscriminator && f.Parent == null);
116+
var targetField = typeInfo.Fields.SingleOrDefault(static f => f.IsTypeDiscriminator && f.Parent == null);
116117
if (targetField == null) {
117118
throw new DomainBuilderException(string.Format(Strings.ExTypeDiscriminatorIsNotFoundForXType, typeInfo.Name));
118119
}
@@ -136,8 +137,8 @@ public void BuildFields(TypeDef typeDef, TypeInfo typeInfo)
136137
{
137138
if (typeInfo.IsInterface) {
138139
var sourceFields = typeInfo.DirectInterfaces
139-
.SelectMany(i => i.Fields)
140-
.Where(f => !f.IsPrimaryKey && f.Parent == null);
140+
.SelectMany(static i => i.Fields)
141+
.Where(static f => !f.IsPrimaryKey && f.Parent == null);
141142
foreach (var srcField in sourceFields) {
142143
if (!typeInfo.Fields.Contains(srcField.Name)) {
143144
BuildInheritedField(typeInfo, srcField);
@@ -147,7 +148,7 @@ public void BuildFields(TypeDef typeDef, TypeInfo typeInfo)
147148
else {
148149
var ancestor = typeInfo.Ancestor;
149150
if (ancestor != null) {
150-
foreach (var srcField in ancestor.Fields.Where(f => !f.IsPrimaryKey && f.Parent == null)) {
151+
foreach (var srcField in ancestor.Fields.Where(static f => !f.IsPrimaryKey && f.Parent == null)) {
151152
if (typeDef.Fields.TryGetValue(srcField.Name, out var fieldDef)) {
152153
if (fieldDef.UnderlyingProperty == null) {
153154
throw new DomainBuilderException(
@@ -184,7 +185,7 @@ public void BuildFields(TypeDef typeDef, TypeInfo typeInfo)
184185
_ = BuildDeclaredField(typeInfo, fieldDef);
185186
}
186187
}
187-
typeInfo.Columns.AddRange(typeInfo.Fields.Where(f => f.Column != null).Select(f => f.Column));
188+
typeInfo.Columns.AddRange(typeInfo.Fields.Where(static f => f.Column != null).Select(static f => f.Column));
188189

189190
if (typeInfo.IsEntity && !IsAuxiliaryType(typeInfo)) {
190191
foreach (var @interface in typeInfo.DirectInterfaces) {
@@ -197,7 +198,7 @@ public void BuildFields(TypeDef typeDef, TypeInfo typeInfo)
197198

198199
private void BuildFieldMap(TypeInfo @interface, TypeInfo implementor)
199200
{
200-
foreach (var field in @interface.Fields.Where(f => f.IsDeclared)) {
201+
foreach (var field in @interface.Fields.Where(static f => f.IsDeclared)) {
201202
var explicitName = context.NameBuilder.BuildExplicitFieldName(field.DeclaringType, field.Name);
202203
if (implementor.Fields.TryGetValue(explicitName, out var implField)) {
203204
implField.IsExplicit = true;
@@ -262,7 +263,7 @@ private FieldInfo BuildDeclaredField(TypeInfo type, FieldDef fieldDef)
262263
}
263264

264265
if (fieldInfo.IsEntity) {
265-
var fields = context.Model.Types[fieldInfo.ValueType].Fields.Where(f => f.IsPrimaryKey);
266+
var fields = context.Model.Types[fieldInfo.ValueType].Fields.Where(static f => f.IsPrimaryKey);
266267
// Adjusting default value if any
267268
if (fields.Count() == 1 && fieldDef.DefaultValue != null) {
268269
fieldInfo.DefaultValue =
@@ -304,7 +305,7 @@ .StructureFieldMapping[new Pair<FieldInfo>(fieldInfo, structureTypeInfo.Fields[f
304305
f.Configuration,
305306
f.TypeFieldName
306307
))
307-
.Select(g => new FullTextFieldDef(g.Name, g.IsAnalyzed) {
308+
.Select(static g => new FullTextFieldDef(g.Name, g.IsAnalyzed) {
308309
Configuration = g.Configuration, TypeFieldName = g.TypeFieldName
309310
}));
310311
}
@@ -471,7 +472,7 @@ private HierarchyInfo BuildHierarchyInfo(TypeInfo root, HierarchyDef hierarchyDe
471472
if (schema != InheritanceSchema.ConcreteTable) {
472473
var node = context.DependencyGraph.TryGetNode(hierarchyDef.Root);
473474
// No dependencies => no descendants
474-
if (node == null || node.IncomingEdges.Count(e => e.Kind == EdgeKind.Inheritance) == 0) {
475+
if (node == null || node.IncomingEdges.Count(static e => e.Kind == EdgeKind.Inheritance) == 0) {
475476
schema = InheritanceSchema.ConcreteTable;
476477
}
477478
}
@@ -490,17 +491,17 @@ private HierarchyInfo BuildHierarchyInfo(TypeInfo root, HierarchyDef hierarchyDe
490491
private KeyInfo BuildKeyInfo(TypeInfo root, HierarchyDef hierarchyDef)
491492
{
492493
var keyFields = root.Fields
493-
.Where(field => field.IsPrimaryKey)
494-
.OrderBy(field => field.MappingInfo.Offset)
494+
.Where(static field => field.IsPrimaryKey)
495+
.OrderBy(static field => field.MappingInfo.Offset)
495496
.ToList();
496497

497498
var keyColumns = keyFields
498-
.Where(field => field.Column != null)
499-
.Select(field => field.Column)
499+
.Where(static field => field.Column != null)
500+
.Select(static field => field.Column)
500501
.ToList();
501502

502503
var keyTupleDescriptor = TupleDescriptor.Create(
503-
keyColumns.Select(c => c.ValueType).ToArray(keyColumns.Count));
504+
keyColumns.Select(static c => c.ValueType).ToArray(keyColumns.Count));
504505
var typeIdColumnIndex = -1;
505506
if (hierarchyDef.IncludeTypeId) {
506507
for (var i = 0; i < keyColumns.Count; i++) {

0 commit comments

Comments
 (0)