Beispiel #1
0
        public static ActiveConstantExpression Create(ConstantExpression constantExpression, ActiveExpressionOptions?options)
        {
            var type  = constantExpression.Type;
            var value = constantExpression.Value;

            if (typeof(Expression).IsAssignableFrom(type))
            {
                var key = new ExpressionInstancesKey((Expression)value, options);
                lock (instanceManagementLock)
                {
                    if (!expressionInstances.TryGetValue(key, out var activeConstantExpression))
                    {
                        activeConstantExpression = new ActiveConstantExpression(type, value, options, key, null);
                        expressionInstances.Add(key, activeConstantExpression);
                    }
                    ++activeConstantExpression.disposalCount;
                    return(activeConstantExpression);
                }
            }
            else
            {
                var key = new InstancesKey(type, value, options);
                lock (instanceManagementLock)
                {
                    if (!instances.TryGetValue(key, out var activeConstantExpression))
                    {
                        activeConstantExpression = new ActiveConstantExpression(type, value, options, null, key);
                        instances.Add(key, activeConstantExpression);
                    }
                    ++activeConstantExpression.disposalCount;
                    return(activeConstantExpression);
                }
            }
        }
Beispiel #2
0
 public int GetHashCode(ExpressionInstancesKey obj) =>
 HashCode.Combine(obj.Expression is null ? 0 : ExpressionEqualityComparer.Default.GetHashCode(obj.Expression), obj.Options);