Files
Umbraco-CMS/src/Umbraco.Core/LambdaExpressionCacheKey.cs
Mole bf41c2eeaa Netcore: Align namespaces (#9801)
* Rename Umbraco.Core namespace to Umbraco.Cms.Core

* Move extension methods in core project to Umbraco.Extensions

* Move extension methods in core project to Umbraco.Extensions

* Rename Umbraco.Examine namespace to Umbraco.Cms.Examine

* Move examine extensions to Umbraco.Extensions namespace

* Reflect changed namespaces in Builder and fix unit tests

* Adjust namespace in Umbraco.ModelsBuilder.Embedded

* Adjust namespace in Umbraco.Persistence.SqlCe

* Adjust namespace in Umbraco.PublishedCache.NuCache

* Align namespaces in Umbraco.Web.BackOffice

* Align namespaces in Umbraco.Web.Common

* Ensure that SqlCeSupport is still enabled after changing the namespace

* Align namespaces in Umbraco.Web.Website

* Align namespaces in Umbraco.Web.UI.NetCore

* Align namespaces in Umbraco.Tests.Common

* Align namespaces in Umbraco.Tests.UnitTests

* Align namespaces in Umbraco.Tests.Integration

* Fix errors caused by changed namespaces

* Fix integration tests

* Undo the Umbraco.Examine.Lucene namespace change

This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows.

* Fix merge

* Fix Merge
2021-02-18 11:06:02 +01:00

84 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace Umbraco.Cms.Core
{
/// <summary>
/// Represents a simple <see cref="LambdaExpression"/> in a form which is suitable for using as a dictionary key
/// by exposing the return type, argument types and expression string form in a single concatenated string.
/// </summary>
public struct LambdaExpressionCacheKey
{
public LambdaExpressionCacheKey(string returnType, string expression, params string[] argTypes)
{
ReturnType = returnType;
ExpressionAsString = expression;
ArgTypes = new HashSet<string>(argTypes);
_toString = null;
}
public LambdaExpressionCacheKey(LambdaExpression obj)
{
ReturnType = obj.ReturnType.FullName;
ExpressionAsString = obj.ToString();
ArgTypes = new HashSet<string>(obj.Parameters.Select(x => x.Type.FullName));
_toString = null;
}
/// <summary>
/// The argument type names of the <see cref="LambdaExpression"/>
/// </summary>
public readonly HashSet<string> ArgTypes;
/// <summary>
/// The return type of the <see cref="LambdaExpression"/>
/// </summary>
public readonly string ReturnType;
/// <summary>
/// The original string representation of the <see cref="LambdaExpression"/>
/// </summary>
public readonly string ExpressionAsString;
private string _toString;
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return _toString ?? (_toString = String.Concat(String.Join("|", ArgTypes), ",", ReturnType, ",", ExpressionAsString));
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(obj, null)) return false;
var casted = (LambdaExpressionCacheKey)obj;
return casted.ToString() == ToString();
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return ToString().GetHashCode();
}
}
}