private static (string Key, MethodInfo Method, object Instance, object[] Arguments) ParseExpression([NotNull] LambdaExpression expression)
        {
            if (expression.Body is not MethodCallExpression methodCall)
            {
                throw new ArgumentNotMethodExpressionException(nameof(expression));
            }

            MethodInfo method   = methodCall.Method;
            object     instance = methodCall.Object != null?GetValue(methodCall.Object) : null;

            object[] arguments = new object[methodCall.Arguments.Count];

            KeyBuilder keyBuilder = new KeyBuilder();

            keyBuilder.By(method.DeclaringType).By(method.MetadataToken).By(method.GetGenericArguments()).By(instance);

            for (int i = 0; i < methodCall.Arguments.Count; ++i)
            {
                keyBuilder.By(arguments[i] = GetValue(methodCall.Arguments[i]));
            }

            string cacheKey = keyBuilder.ToString();

            return(cacheKey, method, instance, arguments);
        }
示例#2
0
        public override bool Equals(object obj)
        {
            if (obj is Attribute attr)
            {
                return(KeyBuilder.ToString().Equals(attr.KeyBuilder.ToString()) &&
                       ValueBuilder.ToString().Equals(attr.ValueBuilder.ToString()));
            }

            return(false);
        }
示例#3
0
        public KeyValueNode BuildNode()
        {
            var toReturn = new KeyValueNode();

            toReturn.Key = KeyBuilder.ToString();
            if (ValueBuilder.Length > 0)
            {
                toReturn.Value = ValueBuilder.ToString();
            }
            else
            {
                toReturn.Children = new Dictionary <string, List <KeyValueNode> >();
            }

            return(toReturn);
        }
        public string GetKey(MethodInfo method, params object[] args)
        {
            var sb      = new StringBuilder();
            var builder = new KeyBuilder(sb);

            BuildKey(builder);

            builder.Append(method.DeclaringType.FullName);
            builder.Append(method.Name);

            foreach (var a in args)
            {
                builder.Append(a);
            }

            return(builder.ToString());
        }