Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/Libraries/SmartStore.Core/Async/AsyncRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Hosting;
using Microsoft.AspNetCore.Hosting;
using Autofac;
using SmartStore.Core.Infrastructure;

Expand Down
3 changes: 0 additions & 3 deletions src/Libraries/SmartStore.Core/Async/LocalAsyncState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public virtual IEnumerable<T> GetAll<T>()
.OfType<T>();
}


public virtual void Set<T>(T state, string name = null, bool neverExpires = false)
{
Guard.NotNull(state, nameof(state));
Expand Down Expand Up @@ -131,7 +130,6 @@ protected virtual bool OnRemoveCancelTokenSource(string key, bool successive = f
return false;
}


public CancellationTokenSource GetCancelTokenSource<T>(string name = null)
{
return OnGetCancelTokenSource(BuildKey<T>(name));
Expand Down Expand Up @@ -180,7 +178,6 @@ protected virtual bool OnCancel(string key, bool successive = false)
return false;
}


protected virtual AsyncStateInfo GetStateInfo<T>(string name = null)
{
return _states.Get(BuildKey<T>(name)) as AsyncStateInfo;
Expand Down
76 changes: 17 additions & 59 deletions src/Libraries/SmartStore.Core/BaseEntity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Core.Objects;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

namespace SmartStore.Core
Expand All @@ -11,94 +7,61 @@ namespace SmartStore.Core
/// Base class for entities
/// </summary>
[DataContract]
public abstract partial class BaseEntity : IEquatable<BaseEntity>
public abstract partial class BaseEntity
{
/// <summary>
/// Gets or sets the entity identifier
/// </summary>
[DataMember]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual string GetEntityName()
{
return GetUnproxiedType().Name;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Type GetUnproxiedType()
{
#region Old
//var t = GetType();
//if (t.AssemblyQualifiedName.StartsWith("System.Data.Entity."))
//{
// // it's a proxied type
// t = t.BaseType;
//}

//return t;
#endregion

return ObjectContext.GetObjectType(GetType());
}

/// <summary>
/// Transient objects are not associated with an item already in storage. For instance,
/// a Product entity is transient if its Id is 0.
/// Checks whether the entity is transient (not persisted to database)
/// </summary>
public virtual bool IsTransientRecord()
/// <returns>True if transient, false otherwise</returns>
public bool IsTransient()
{
return Id == 0;
}

public override bool Equals(object obj)
{
return this.Equals(obj as BaseEntity);
return Equals(obj as BaseEntity);
}

private static bool IsTransient(BaseEntity obj)
{
return obj != null && Equals(obj.Id, default(int));
}

bool IEquatable<BaseEntity>.Equals(BaseEntity other)
private Type GetUnproxiedType()
{
return this.Equals(other);
return GetType();
}

protected virtual bool Equals(BaseEntity other)
public virtual bool Equals(BaseEntity other)
{
if (other == null)
return false;

if (ReferenceEquals(this, other))
return true;

if (HasSameNonDefaultIds(other))
if (!IsTransient(this) && !IsTransient(other) && Equals(Id, other.Id))
{
var otherType = other.GetUnproxiedType();
var thisType = GetUnproxiedType();
return thisType.Equals(otherType);
return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType);
}

return false;
}

[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode()
{
if (IsTransientRecord())
{
if (Equals(Id, default(int)))
return base.GetHashCode();
}
else
{
unchecked
{
// It's possible for two objects to return the same hash code based on
// identically valued properties, even if they're of two different types,
// so we include the object's type in the hash calculation
var hashCode = GetUnproxiedType().GetHashCode();
return (hashCode * 31) ^ Id.GetHashCode();
}
}
return Id.GetHashCode();
}

public static bool operator ==(BaseEntity x, BaseEntity y)
Expand All @@ -110,10 +73,5 @@ public override int GetHashCode()
{
return !(x == y);
}

private bool HasSameNonDefaultIds(BaseEntity other)
{
return !this.IsTransientRecord() && !other.IsTransientRecord() && this.Id == other.Id;
}
}
}
1 change: 0 additions & 1 deletion src/Libraries/SmartStore.Core/Caching/NullCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public Task<T> GetAsync<T>(string key, Func<Task<T>> acquirer, TimeSpan? duratio
return acquirer();
}


public ISet GetHashSet(string key, Func<IEnumerable<string>> acquirer = null)
{
return new MemorySet(this);
Expand Down
3 changes: 3 additions & 0 deletions src/Libraries/SmartStore.Core/Caching/RequestCache.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if false // TODO: .NET 8 migration - temporarily disabled
ο»Ώusing System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -132,3 +133,5 @@ protected override void OnDispose(bool disposing)
}
}
}

#endif
1 change: 0 additions & 1 deletion src/Libraries/SmartStore.Core/Collections/TreeNodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ private void AttachTo(T newParent, int? index)
? _children.Where(x => !x.IsLeaf)
: Enumerable.Empty<T>();


[JsonIgnore]
public T FirstChild => _children?.FirstOrDefault();

Expand Down
3 changes: 0 additions & 3 deletions src/Libraries/SmartStore.Core/ComponentModel/FastProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ public static FastProperty Create(PropertyInfo property)
return new DelegatedAccessor(property);
}


/// <summary>
/// <para>
/// Creates and caches fast property helpers that expose getters for every non-hidden get property
Expand Down Expand Up @@ -470,8 +469,6 @@ public PropertyKey(Type type, string propertyName)
}
}



[DebuggerDisplay("DelegateAccessor: {Name}")]
internal sealed class DelegatedAccessor : FastProperty
{
Expand Down
5 changes: 0 additions & 5 deletions src/Libraries/SmartStore.Core/ComponentModel/HybridExpando.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public override IEnumerable<string> GetDynamicMemberNames()
}
}


/// <summary>
/// Try to retrieve a member by name first from instance properties
/// followed by the collection entries.
Expand Down Expand Up @@ -216,7 +215,6 @@ protected virtual bool TryGetMemberCore(string name, out object result)
return exists;
}


/// <summary>
/// Property setter implementation tries to retrieve value from instance
/// first then into this object
Expand Down Expand Up @@ -293,7 +291,6 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
return false;
}


/// <summary>
/// Reflection Helper method to retrieve a property
/// </summary>
Expand Down Expand Up @@ -353,7 +350,6 @@ protected bool InvokeMethod(object instance, string name, object[] args, out obj
return false;
}


/// <summary>
/// Convenience method that provides a string Indexer
/// to the Properties collection AND the strongly typed
Expand Down Expand Up @@ -387,7 +383,6 @@ public object this[string key]
set => TrySetMemberCore(key, value);
}


/// <summary>
/// Returns all properties
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions src/Libraries/SmartStore.Core/ComponentModel/PropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public static string MapTypeToXmlType(Type type)
//return type.ToString().ToLower();
}


public static Type MapXmlTypeToType(string xmlType)
{
xmlType = xmlType.ToLower();
Expand Down Expand Up @@ -138,7 +137,6 @@ public static Type MapXmlTypeToType(string xmlType)
if (xmlType == "base64binary")
return typeof(byte[]);


// return null if no match is found
// don't throw so the caller can decide more efficiently what to do
// with this error result
Expand All @@ -158,7 +156,6 @@ public System.Xml.Schema.XmlSchema GetSchema()
return null;
}


/// <summary>
/// Serializes the dictionary to XML. Keys are
/// serialized to element names and values as
Expand Down Expand Up @@ -211,7 +208,6 @@ public void WriteXml(System.Xml.XmlWriter writer)
writer.WriteEndAttribute();
}


// Serialize simple types with WriteValue
if (!isCustom)
{
Expand All @@ -231,7 +227,6 @@ public void WriteXml(System.Xml.XmlWriter writer)
}
}


/// <summary>
/// Reads the custom serialized format
/// </summary>
Expand Down Expand Up @@ -281,7 +276,6 @@ public void ReadXml(System.Xml.XmlReader reader)
}
}


/// <summary>
/// Serializes this dictionary to an XML string
/// </summary>
Expand Down Expand Up @@ -319,7 +313,6 @@ public bool FromXml(string xml)
return true;
}


/// <summary>
/// Creates an instance of a propertybag from an Xml string
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public static bool SerializeObject(object instance, XmlTextWriter writer, bool t
return retVal;
}


/// <summary>
/// Serializes an object into an XML string variable for easy 'manual' serialization
/// </summary>
Expand Down Expand Up @@ -255,8 +254,6 @@ public static byte[] SerializeObjectToByteArray(object instance, bool throwExcep
return byteResult;
}



/// <summary>
/// Deserializes an object from file and returns a reference.
/// </summary>
Expand Down Expand Up @@ -399,7 +396,6 @@ public static object DeSerializeObject(byte[] buffer, Type objectType, bool thro
return Instance;
}


/// <summary>
/// Returns a string of all the field value pairs of a given object.
/// Works only on non-statics.
Expand Down Expand Up @@ -455,6 +451,3 @@ public enum ObjectToStringTypes
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Web.Routing;
using Microsoft.AspNetCore.Routing;
using SmartStore.Utilities;

namespace SmartStore.ComponentModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.Web.Routing;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json.Linq;
using SmartStore.Core.Domain.Catalog;
using SmartStore.Core.Domain.Shipping;
Expand Down
Loading