Skip to content

Remove ReadOnlyDictionary safety wrappers #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Orm/Xtensive.Orm/Orm/Building/Builders/TypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private FieldInfo BuildDeclaredField(TypeInfo type, FieldDef fieldDef)
currentIndex.Fields.AddRange(structureFullTextIndex.Fields
.Select(f => (
fieldInfo.DeclaringType
.StructureFieldMapping[new Pair<FieldInfo>(fieldInfo, structureTypeInfo.Fields[f.Name])].Name,
.StructureFieldMapping[(fieldInfo, structureTypeInfo.Fields[f.Name])].Name,
f.IsAnalyzed,
f.Configuration,
f.TypeFieldName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2003-2016 Xtensive LLC.
// Copyright (C) 2003-2016 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
Expand All @@ -16,6 +16,6 @@ public interface IWeightedTerm : IOperand
/// <summary>
/// Terms mapped to its weights.
/// </summary>
IDictionary<IWeighableTerm, float?> WeighedTerms { get; }
IReadOnlyDictionary<IWeighableTerm, float?> WeighedTerms { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2003-2016 Xtensive LLC.
// Copyright (C) 2003-2016 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
Expand All @@ -17,7 +17,7 @@ public interface IWeightedTermConstructionFlow
/// <summary>
/// Constructed operands.
/// </summary>
IDictionary<IWeighableTerm, float?> WeightedOperands { get; }
IReadOnlyDictionary<IWeighableTerm, float?> WeightedOperands { get; }

/// <summary>
/// Adds <see cref="ISimpleTerm"/> to collection of operands with no specified weight.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2003-2016 Xtensive LLC.
// Copyright (C) 2003-2016 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
Expand Down Expand Up @@ -62,7 +62,7 @@ public static CustomProximityTerm CreateCustomProximityTerm(IOperator source, IC
return new CustomProximityTerm(source, terms, maximumDistance, matchOrder);
}

public static WeightedTerm CreateWeightedTerm(IOperator source, IDictionary<IWeighableTerm, float?> weightedTerms)
public static WeightedTerm CreateWeightedTerm(IOperator source, IReadOnlyDictionary<IWeighableTerm, float?> weightedTerms)
{
return new WeightedTerm(source, weightedTerms);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace Xtensive.Orm.FullTextSearchCondition.Nodes
public sealed class WeightedTerm : Operand, IWeightedTerm
{
/// <inheritdoc/>
public IDictionary<IWeighableTerm, float?> WeighedTerms { get; private set; }
public IReadOnlyDictionary<IWeighableTerm, float?> WeighedTerms { get; }

protected override void AcceptVisitorInternal(ISearchConditionNodeVisitor visitor)
{
visitor.Visit(this);
}

internal WeightedTerm(IOperator source, IDictionary<IWeighableTerm, float?> weightedTerms)
internal WeightedTerm(IOperator source, IReadOnlyDictionary<IWeighableTerm, float?> weightedTerms)
: base(SearchConditionNodeType.WeightedTerm, source)
{
WeighedTerms = weightedTerms;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2003-2016 Xtensive LLC.
// Copyright (C) 2003-2016 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
Expand All @@ -10,18 +10,17 @@
using System.Globalization;
using Xtensive.Orm.FullTextSearchCondition.Interfaces;
using Xtensive.Orm.FullTextSearchCondition.Internals;
using Xtensive.Core;

namespace Xtensive.Orm.FullTextSearchCondition
{
public sealed class WeightedTermEndpoint : IWeightedTermConstructionFlow
{
private readonly IDictionary<IWeighableTerm, float?> weightedOperands;
private readonly Dictionary<IWeighableTerm, float?> weightedOperands;
private readonly IOperator rootOperator;

IDictionary<IWeighableTerm, float?> IWeightedTermConstructionFlow.WeightedOperands
{
get { return new ReadOnlyDictionary<IWeighableTerm, float?>(weightedOperands); }
}
IReadOnlyDictionary<IWeighableTerm, float?> IWeightedTermConstructionFlow.WeightedOperands =>
weightedOperands.AsSafeWrapper();

public IWeightedTermConstructionFlow SimpleTerm(string term)
{
Expand Down
6 changes: 2 additions & 4 deletions Orm/Xtensive.Orm/Orm/Internals/RemapContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2014 Xtensive LLC.
// Copyright (C) 2014 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kulakov
Expand All @@ -18,9 +18,7 @@ internal sealed class RemapContext
/// <summary>
/// Gets maps from local key to actual(storage) key.
/// </summary>
public KeyMapping KeyMapping {
get { return new KeyMapping(keyMap); }
}
public KeyMapping KeyMapping => new KeyMapping(keyMap.AsSafeWrapper());

/// <summary>
/// Gets entities which need to be remap.
Expand Down
6 changes: 3 additions & 3 deletions Orm/Xtensive.Orm/Orm/KeyMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ orderby pairKeyString
/// <summary>
/// Initializes a new instance of this class.
/// </summary>
public KeyMapping(IDictionary<Key,Key> map)
public KeyMapping(IReadOnlyDictionary<Key,Key> map)
{
Map = new ReadOnlyDictionary<Key, Key>(map);
Map = map;
}

// Serialization
Expand Down Expand Up @@ -100,7 +100,7 @@ private KeyMapping(SerializationInfo info, StreamingContext context)
var map = new Dictionary<Key, Key>();
foreach (var pair in serializedMapping)
map.Add(pair.Key, pair.Value);
Map = new ReadOnlyDictionary<Key, Key>(map);
Map = map.AsSafeWrapper();
}
}
}
18 changes: 7 additions & 11 deletions Orm/Xtensive.Orm/Orm/Model/TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static readonly Type
private bool isInboundOnly;
private KeyInfo key;
private bool hasVersionRoots;
private IDictionary<Pair<FieldInfo>, FieldInfo> structureFieldMapping;
private IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> structureFieldMapping;
private List<AssociationInfo> overridenAssociations;
private FieldInfo typeIdField;

Expand Down Expand Up @@ -522,12 +522,8 @@ public bool HasVersionRoots
/// Gets the structure field mapping.
/// </summary>
/// <value>The structure field mapping.</value>
public IDictionary<Pair<FieldInfo>, FieldInfo> StructureFieldMapping
{
get {
return structureFieldMapping ?? BuildStructureFieldMapping();
}
}
public IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> StructureFieldMapping =>
structureFieldMapping ?? BuildStructureFieldMapping();

/// <summary>
/// Gets <see cref="IObjectValidator"/> instances
Expand Down Expand Up @@ -902,16 +898,16 @@ private void BuildVersionExtractor()
VersionExtractor = new MapTransform(true, versionTupleDescriptor, map);
}

private IDictionary<Pair<FieldInfo>, FieldInfo> BuildStructureFieldMapping()
private IReadOnlyDictionary<(FieldInfo, FieldInfo), FieldInfo> BuildStructureFieldMapping()
{
var result = new Dictionary<Pair<FieldInfo>, FieldInfo>();
var result = new Dictionary<(FieldInfo, FieldInfo), FieldInfo>();
var structureFields = Fields.Where(f => f.IsStructure && f.Parent == null);
foreach (var structureField in structureFields) {
var structureTypeInfo = Model.Types[structureField.ValueType];
foreach (var pair in structureTypeInfo.Fields.Zip(structureField.Fields, (first, second) => (first, second)))
result.Add(new Pair<FieldInfo>(structureField, pair.first), pair.second);
result.Add((structureField, pair.first), pair.second);
}
return new ReadOnlyDictionary<Pair<FieldInfo>, FieldInfo>(result);
return result.AsSafeWrapper();
}

private static IEnumerable<FieldInfo> GetBaseFields(Type type, IEnumerable<FieldInfo> fields, bool bRoot)
Expand Down
3 changes: 1 addition & 2 deletions Orm/Xtensive.Orm/Orm/Persistent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ internal void SetNormalizedFieldValue(FieldInfo field, object value, SyncContext
var currentField = field;
var structure = persistent as Structure;
while (structure != null && structure.Owner != null) {
var pair = new Pair<FieldInfo>(structure.Field, currentField);
currentField = structure.Owner.TypeInfo.StructureFieldMapping[pair];
currentField = structure.Owner.TypeInfo.StructureFieldMapping[(structure.Field, currentField)];
persistent = structure.Owner;
structure = persistent as Structure;
}
Expand Down
14 changes: 7 additions & 7 deletions Orm/Xtensive.Orm/Orm/Structure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ internal override sealed void SystemBeforeGetValue(FieldInfo field)
}
if (Owner == null)
return;
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
Owner.SystemBeforeGetValue(ownerField);
}

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

internal override sealed void SystemGetValueCompleted(FieldInfo field, object value, Exception exception)
{
if (Owner == null)
return;
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
Owner.SystemGetValueCompleted(ownerField, value, exception);
}

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

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

Expand Down Expand Up @@ -273,15 +273,15 @@ internal override sealed void SystemSetValue(FieldInfo field, object oldValue, o
}
if (Owner == null)
return;
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
Owner.SystemSetValue(ownerField, oldValue, newValue);
}

internal override sealed void SystemSetValueCompleted(FieldInfo field, object oldValue, object newValue, Exception exception)
{
if (Owner == null)
return;
var ownerField = Owner.TypeInfo.StructureFieldMapping[new Pair<FieldInfo>(Field, field)];
var ownerField = Owner.TypeInfo.StructureFieldMapping[(Field, field)];
Owner.SystemSetValueCompleted(ownerField, oldValue, newValue, exception);
}

Expand Down
Loading