Revert various changes
This commit is contained in:
41
src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs
Normal file
41
src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a composite key of (string, string) for fast dictionaries.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The string parts of the key are case-insensitive.</para>
|
||||
/// <para>Null is a valid value for both parts.</para>
|
||||
/// </remarks>
|
||||
public struct CompositeNStringNStringKey : IEquatable<CompositeNStringNStringKey>
|
||||
{
|
||||
private readonly string _key1;
|
||||
private readonly string _key2;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompositeNStringNStringKey"/> struct.
|
||||
/// </summary>
|
||||
public CompositeNStringNStringKey(string key1, string key2)
|
||||
{
|
||||
_key1 = key1?.ToLowerInvariant() ?? "NULL";
|
||||
_key2 = key2?.ToLowerInvariant() ?? "NULL";
|
||||
}
|
||||
|
||||
public bool Equals(CompositeNStringNStringKey other)
|
||||
=> _key2 == other._key2 && _key1 == other._key1;
|
||||
|
||||
public override bool Equals(object obj)
|
||||
=> obj is CompositeNStringNStringKey other && _key2 == other._key2 && _key1 == other._key1;
|
||||
|
||||
public override int GetHashCode()
|
||||
=> _key2.GetHashCode() * 31 + _key1.GetHashCode();
|
||||
|
||||
public static bool operator ==(CompositeNStringNStringKey key1, CompositeNStringNStringKey key2)
|
||||
=> key1._key2 == key2._key2 && key1._key1 == key2._key1;
|
||||
|
||||
public static bool operator !=(CompositeNStringNStringKey key1, CompositeNStringNStringKey key2)
|
||||
=> key1._key2 != key2._key2 || key1._key1 != key2._key1;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Umbraco.Core.Collections
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The string parts of the key are case-insensitive.</para>
|
||||
/// <para>Null is a valid value for both parts.</para>
|
||||
/// <para>Null is NOT a valid value for neither parts.</para>
|
||||
/// </remarks>
|
||||
public struct CompositeStringStringKey : IEquatable<CompositeStringStringKey>
|
||||
{
|
||||
@@ -19,12 +19,8 @@ namespace Umbraco.Core.Collections
|
||||
/// </summary>
|
||||
public CompositeStringStringKey(string key1, string key2)
|
||||
{
|
||||
// fixme temp - debugging
|
||||
if (key1 == null) throw new Exception("Getting null culture in CompositeStringStringKey constructor, fix!");
|
||||
if (key2 == null) throw new Exception("Getting null segment in CompositeStringStringKey constructor, fix!");
|
||||
|
||||
_key1 = key1?.ToLowerInvariant() ?? "NULL";
|
||||
_key2 = key2?.ToLowerInvariant() ?? "NULL";
|
||||
_key1 = key1?.ToLowerInvariant() ?? throw new ArgumentNullException(nameof(key1));
|
||||
_key2 = key2?.ToLowerInvariant() ?? throw new ArgumentNullException(nameof(key2));
|
||||
}
|
||||
|
||||
public bool Equals(CompositeStringStringKey other)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
private List<PropertyValue> _values = new List<PropertyValue>();
|
||||
private PropertyValue _pvalue;
|
||||
private Dictionary<CompositeStringStringKey, PropertyValue> _vvalues;
|
||||
private Dictionary<CompositeNStringNStringKey, PropertyValue> _vvalues;
|
||||
|
||||
private static readonly Lazy<PropertySelectors> Ps = new Lazy<PropertySelectors>();
|
||||
|
||||
@@ -77,8 +77,8 @@ namespace Umbraco.Core.Models
|
||||
|
||||
// custom comparer for enumerable
|
||||
// ReSharper disable once MergeCastWithTypeCheck
|
||||
if (o is IEnumerable && o1 is IEnumerable)
|
||||
return ((IEnumerable) o).Cast<object>().UnsortedSequenceEqual(((IEnumerable) o1).Cast<object>());
|
||||
if (o is IEnumerable && o1 is IEnumerable enumerable)
|
||||
return ((IEnumerable) o).Cast<object>().UnsortedSequenceEqual(enumerable.Cast<object>());
|
||||
|
||||
return o.Equals(o1);
|
||||
}, o => o.GetHashCode());
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Core.Models
|
||||
_values = value.Where(x => PropertyType.ValidateVariation(x.Culture, x.Segment, false)).ToList();
|
||||
_pvalue = _values.FirstOrDefault(x => x.Culture == null && x.Segment == null);
|
||||
_vvalues = _values.Count > (_pvalue == null ? 0 : 1)
|
||||
? _values.Where(x => x != _pvalue).ToDictionary(x => new CompositeStringStringKey(x.Culture, x.Segment), x => x)
|
||||
? _values.Where(x => x != _pvalue).ToDictionary(x => new CompositeNStringNStringKey(x.Culture, x.Segment), x => x)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace Umbraco.Core.Models
|
||||
if (!PropertyType.ValidateVariation(culture, segment, false)) return null;
|
||||
if (culture == null && segment == null) return GetPropertyValue(_pvalue, published);
|
||||
if (_vvalues == null) return null;
|
||||
return _vvalues.TryGetValue(new CompositeStringStringKey(culture, segment), out var pvalue)
|
||||
return _vvalues.TryGetValue(new CompositeNStringNStringKey(culture, segment), out var pvalue)
|
||||
? GetPropertyValue(pvalue, published)
|
||||
: null;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
PropertyType.ValidateVariation(culture, segment, true);
|
||||
|
||||
(var pvalue, _) = GetPValue(culture, segment, false);
|
||||
var (pvalue, _) = GetPValue(culture, segment, false);
|
||||
if (pvalue == null) return;
|
||||
PublishPropertyValue(pvalue);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ namespace Umbraco.Core.Models
|
||||
internal void ClearPublishedValue(string culture = null, string segment = null)
|
||||
{
|
||||
PropertyType.ValidateVariation(culture, segment, true);
|
||||
(var pvalue, _) = GetPValue(culture, segment, false);
|
||||
var (pvalue, _) = GetPValue(culture, segment, false);
|
||||
if (pvalue == null) return;
|
||||
ClearPublishedPropertyValue(pvalue);
|
||||
}
|
||||
@@ -271,12 +271,8 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
public void SetValue(object value, string culture = null, string segment = null)
|
||||
{
|
||||
if (PropertyType.Variations == ContentVariation.InvariantNeutral)
|
||||
{
|
||||
culture = null;
|
||||
}
|
||||
PropertyType.ValidateVariation(culture, segment, true);
|
||||
(var pvalue, var change) = GetPValue(culture, segment, true);
|
||||
var (pvalue, change) = GetPValue(culture, segment, true);
|
||||
|
||||
var origValue = pvalue.EditedValue;
|
||||
var setValue = PropertyType.ConvertAssignedValue(value);
|
||||
@@ -289,7 +285,7 @@ namespace Umbraco.Core.Models
|
||||
// bypasses all changes detection and is the *only* way to set the published value
|
||||
internal void FactorySetValue(string culture, string segment, bool published, object value)
|
||||
{
|
||||
(var pvalue, _) = GetPValue(culture, segment, true);
|
||||
var (pvalue, _) = GetPValue(culture, segment, true);
|
||||
|
||||
if (published && PropertyType.IsPublishing)
|
||||
pvalue.PublishedValue = value;
|
||||
@@ -319,10 +315,10 @@ namespace Umbraco.Core.Models
|
||||
if (_vvalues == null)
|
||||
{
|
||||
if (!create) return (null, false);
|
||||
_vvalues = new Dictionary<CompositeStringStringKey, PropertyValue>();
|
||||
_vvalues = new Dictionary<CompositeNStringNStringKey, PropertyValue>();
|
||||
change = true;
|
||||
}
|
||||
var k = new CompositeStringStringKey(culture, segment);
|
||||
var k = new CompositeNStringNStringKey(culture, segment);
|
||||
if (!_vvalues.TryGetValue(k, out var pvalue))
|
||||
{
|
||||
if (!create) return (null, false);
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
<Compile Include="CodeAnnotations\UmbracoProposedPublicAttribute.cs" />
|
||||
<Compile Include="CodeAnnotations\UmbracoUdiTypeAttribute.cs" />
|
||||
<Compile Include="CodeAnnotations\UmbracoWillObsoleteAttribute.cs" />
|
||||
<Compile Include="Collections\CompositeNStringNStringKey.cs" />
|
||||
<Compile Include="Collections\CompositeStringStringKey.cs" />
|
||||
<Compile Include="Collections\CompositeIntStringKey.cs" />
|
||||
<Compile Include="Collections\CompositeTypeTypeKey.cs" />
|
||||
|
||||
@@ -499,9 +499,10 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
for (int i = 0; i < entities.Length; i++)
|
||||
{
|
||||
Assert.AreEqual(0, entities[i].AdditionalData.Count);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
Assert.AreEqual(1, entities[i].AdditionalData.Count);
|
||||
var doc = (IDocumentEntitySlim)entities[i];
|
||||
var keys = doc.CultureNames.Keys.ToList();
|
||||
var vals = doc.CultureNames.Values.ToList();
|
||||
|
||||
@@ -53,11 +53,6 @@ namespace Umbraco.Web.Models.Mapping
|
||||
//a language Id needs to be set for a property type that can be varried by language
|
||||
throw new InvalidOperationException($"No languageId found in mapping operation when one is required for the culture neutral property type {property.PropertyType.Alias}");
|
||||
}
|
||||
if (property.PropertyType.Variations == ContentVariation.InvariantNeutral)
|
||||
{
|
||||
culture = null;
|
||||
|
||||
}
|
||||
|
||||
var result = new TDestination
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user