Skip to content

Commit 879d343

Browse files
authored
Remove ReadOnlyDictionary safety wrapper in TypeInfo (#193)
1 parent e66e94c commit 879d343

File tree

11 files changed

+34
-42
lines changed

11 files changed

+34
-42
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private FieldInfo BuildDeclaredField(TypeInfo type, FieldDef fieldDef)
303303
currentIndex.Fields.AddRange(structureFullTextIndex.Fields
304304
.Select(f => (
305305
fieldInfo.DeclaringType
306-
.StructureFieldMapping[new Pair<FieldInfo>(fieldInfo, structureTypeInfo.Fields[f.Name])].Name,
306+
.StructureFieldMapping[(fieldInfo, structureTypeInfo.Fields[f.Name])].Name,
307307
f.IsAnalyzed,
308308
f.Configuration,
309309
f.TypeFieldName

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Interfaces/IWeightedTerm.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2003-2016 Xtensive LLC.
1+
// Copyright (C) 2003-2016 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -16,6 +16,6 @@ public interface IWeightedTerm : IOperand
1616
/// <summary>
1717
/// Terms mapped to its weights.
1818
/// </summary>
19-
IDictionary<IWeighableTerm, float?> WeighedTerms { get; }
19+
IReadOnlyDictionary<IWeighableTerm, float?> WeighedTerms { get; }
2020
}
2121
}

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Interfaces/IWeightedTermConstructionFlow.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2003-2016 Xtensive LLC.
1+
// Copyright (C) 2003-2016 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -17,7 +17,7 @@ public interface IWeightedTermConstructionFlow
1717
/// <summary>
1818
/// Constructed operands.
1919
/// </summary>
20-
IDictionary<IWeighableTerm, float?> WeightedOperands { get; }
20+
IReadOnlyDictionary<IWeighableTerm, float?> WeightedOperands { get; }
2121

2222
/// <summary>
2323
/// Adds <see cref="ISimpleTerm"/> to collection of operands with no specified weight.

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Internals/SearchConditionNodeFactory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2003-2016 Xtensive LLC.
1+
// Copyright (C) 2003-2016 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -62,7 +62,7 @@ public static CustomProximityTerm CreateCustomProximityTerm(IOperator source, IC
6262
return new CustomProximityTerm(source, terms, maximumDistance, matchOrder);
6363
}
6464

65-
public static WeightedTerm CreateWeightedTerm(IOperator source, IDictionary<IWeighableTerm, float?> weightedTerms)
65+
public static WeightedTerm CreateWeightedTerm(IOperator source, IReadOnlyDictionary<IWeighableTerm, float?> weightedTerms)
6666
{
6767
return new WeightedTerm(source, weightedTerms);
6868
}

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Nodes/WeightedTerm.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ namespace Xtensive.Orm.FullTextSearchCondition.Nodes
1515
public sealed class WeightedTerm : Operand, IWeightedTerm
1616
{
1717
/// <inheritdoc/>
18-
public IDictionary<IWeighableTerm, float?> WeighedTerms { get; private set; }
18+
public IReadOnlyDictionary<IWeighableTerm, float?> WeighedTerms { get; }
1919

2020
protected override void AcceptVisitorInternal(ISearchConditionNodeVisitor visitor)
2121
{
2222
visitor.Visit(this);
2323
}
2424

25-
internal WeightedTerm(IOperator source, IDictionary<IWeighableTerm, float?> weightedTerms)
25+
internal WeightedTerm(IOperator source, IReadOnlyDictionary<IWeighableTerm, float?> weightedTerms)
2626
: base(SearchConditionNodeType.WeightedTerm, source)
2727
{
2828
WeighedTerms = weightedTerms;

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/WeightedTermEndpoint.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2003-2016 Xtensive LLC.
1+
// Copyright (C) 2003-2016 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -10,18 +10,17 @@
1010
using System.Globalization;
1111
using Xtensive.Orm.FullTextSearchCondition.Interfaces;
1212
using Xtensive.Orm.FullTextSearchCondition.Internals;
13+
using Xtensive.Core;
1314

1415
namespace Xtensive.Orm.FullTextSearchCondition
1516
{
1617
public sealed class WeightedTermEndpoint : IWeightedTermConstructionFlow
1718
{
18-
private readonly IDictionary<IWeighableTerm, float?> weightedOperands;
19+
private readonly Dictionary<IWeighableTerm, float?> weightedOperands;
1920
private readonly IOperator rootOperator;
2021

21-
IDictionary<IWeighableTerm, float?> IWeightedTermConstructionFlow.WeightedOperands
22-
{
23-
get { return new ReadOnlyDictionary<IWeighableTerm, float?>(weightedOperands); }
24-
}
22+
IReadOnlyDictionary<IWeighableTerm, float?> IWeightedTermConstructionFlow.WeightedOperands =>
23+
weightedOperands.AsSafeWrapper();
2524

2625
public IWeightedTermConstructionFlow SimpleTerm(string term)
2726
{

Orm/Xtensive.Orm/Orm/Internals/RemapContext.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2014 Xtensive LLC.
1+
// Copyright (C) 2014 Xtensive LLC.
22
// All rights reserved.
33
// For conditions of distribution and use, see license.
44
// Created by: Alexey Kulakov
@@ -18,9 +18,7 @@ internal sealed class RemapContext
1818
/// <summary>
1919
/// Gets maps from local key to actual(storage) key.
2020
/// </summary>
21-
public KeyMapping KeyMapping {
22-
get { return new KeyMapping(keyMap); }
23-
}
21+
public KeyMapping KeyMapping => new KeyMapping(keyMap.AsSafeWrapper());
2422

2523
/// <summary>
2624
/// Gets entities which need to be remap.

Orm/Xtensive.Orm/Orm/KeyMapping.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ orderby pairKeyString
7070
/// <summary>
7171
/// Initializes a new instance of this class.
7272
/// </summary>
73-
public KeyMapping(IDictionary<Key,Key> map)
73+
public KeyMapping(IReadOnlyDictionary<Key,Key> map)
7474
{
75-
Map = new ReadOnlyDictionary<Key, Key>(map);
75+
Map = map;
7676
}
7777

7878
// Serialization
@@ -100,7 +100,7 @@ private KeyMapping(SerializationInfo info, StreamingContext context)
100100
var map = new Dictionary<Key, Key>();
101101
foreach (var pair in serializedMapping)
102102
map.Add(pair.Key, pair.Value);
103-
Map = new ReadOnlyDictionary<Key, Key>(map);
103+
Map = map.AsSafeWrapper();
104104
}
105105
}
106106
}

Orm/Xtensive.Orm/Orm/Model/TypeInfo.cs

+7-11
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static readonly Type
7575
private bool isInboundOnly;
7676
private KeyInfo key;
7777
private bool hasVersionRoots;
78-
private IDictionary<Pair<FieldInfo>, FieldInfo> structureFieldMapping;
78+
private IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> structureFieldMapping;
7979
private List<AssociationInfo> overridenAssociations;
8080
private FieldInfo typeIdField;
8181

@@ -522,12 +522,8 @@ public bool HasVersionRoots
522522
/// Gets the structure field mapping.
523523
/// </summary>
524524
/// <value>The structure field mapping.</value>
525-
public IDictionary<Pair<FieldInfo>, FieldInfo> StructureFieldMapping
526-
{
527-
get {
528-
return structureFieldMapping ?? BuildStructureFieldMapping();
529-
}
530-
}
525+
public IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> StructureFieldMapping =>
526+
structureFieldMapping ?? BuildStructureFieldMapping();
531527

532528
/// <summary>
533529
/// Gets <see cref="IObjectValidator"/> instances
@@ -903,16 +899,16 @@ private void BuildVersionExtractor()
903899
VersionExtractor = new MapTransform(true, versionTupleDescriptor, map);
904900
}
905901

906-
private IDictionary<Pair<FieldInfo>, FieldInfo> BuildStructureFieldMapping()
902+
private IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> BuildStructureFieldMapping()
907903
{
908-
var result = new Dictionary<Pair<FieldInfo>, FieldInfo>();
904+
var result = new Dictionary<(FieldInfo, FieldInfo), FieldInfo>();
909905
var structureFields = Fields.Where(f => f.IsStructure && f.Parent == null);
910906
foreach (var structureField in structureFields) {
911907
var structureTypeInfo = Model.Types[structureField.ValueType];
912908
foreach (var pair in structureTypeInfo.Fields.Zip(structureField.Fields, (first, second) => (first, second)))
913-
result.Add(new Pair<FieldInfo>(structureField, pair.first), pair.second);
909+
result.Add((structureField, pair.first), pair.second);
914910
}
915-
return new ReadOnlyDictionary<Pair<FieldInfo>, FieldInfo>(result);
911+
return result.AsSafeWrapper();
916912
}
917913

918914
private static IEnumerable<FieldInfo> GetBaseFields(Type type, IEnumerable<FieldInfo> fields, bool bRoot)

Orm/Xtensive.Orm/Orm/Persistent.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ internal void SetNormalizedFieldValue(FieldInfo field, object value, SyncContext
422422
var currentField = field;
423423
var structure = persistent as Structure;
424424
while (structure != null && structure.Owner != null) {
425-
var pair = new Pair<FieldInfo>(structure.Field, currentField);
426-
currentField = structure.Owner.TypeInfo.StructureFieldMapping[pair];
425+
currentField = structure.Owner.TypeInfo.StructureFieldMapping[(structure.Field, currentField)];
427426
persistent = structure.Owner;
428427
structure = persistent as Structure;
429428
}

Orm/Xtensive.Orm/Orm/Structure.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ internal override sealed void SystemBeforeGetValue(FieldInfo field)
186186
}
187187
if (Owner == null)
188188
return;
189-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
189+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
190190
Owner.SystemBeforeGetValue(ownerField);
191191
}
192192

@@ -201,15 +201,15 @@ internal override sealed void SystemGetValue(FieldInfo field, object value)
201201
}
202202
if (Owner == null)
203203
return;
204-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
204+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
205205
Owner.SystemGetValue(ownerField, value);
206206
}
207207

208208
internal override sealed void SystemGetValueCompleted(FieldInfo field, object value, Exception exception)
209209
{
210210
if (Owner == null)
211211
return;
212-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
212+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
213213
Owner.SystemGetValueCompleted(ownerField, value, exception);
214214
}
215215

@@ -225,7 +225,7 @@ internal override sealed void SystemSetValueAttempt(FieldInfo field, object valu
225225
}
226226
if (Owner == null)
227227
return;
228-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
228+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
229229
Owner.SystemSetValueAttempt(ownerField, value);
230230
}
231231

@@ -240,7 +240,7 @@ internal override sealed void SystemBeforeSetValue(FieldInfo field, object value
240240
}
241241
if (Owner == null)
242242
return;
243-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
243+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
244244
Owner.SystemBeforeSetValue(ownerField, value);
245245
}
246246

@@ -273,15 +273,15 @@ internal override sealed void SystemSetValue(FieldInfo field, object oldValue, o
273273
}
274274
if (Owner == null)
275275
return;
276-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
276+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
277277
Owner.SystemSetValue(ownerField, oldValue, newValue);
278278
}
279279

280280
internal override sealed void SystemSetValueCompleted(FieldInfo field, object oldValue, object newValue, Exception exception)
281281
{
282282
if (Owner == null)
283283
return;
284-
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
284+
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
285285
Owner.SystemSetValueCompleted(ownerField, oldValue, newValue, exception);
286286
}
287287

0 commit comments

Comments
 (0)