开发者

Creating an IDictionary<string,Expression> proving difficult

开发者 https://www.devze.com 2023-03-21 03:32 出处:网络
I want to make a dictionary that has named LINQ Expressions, since I cannot store the expressions in my database. I will store the name of the expression that is needed,开发者_运维技巧 and a structure

I want to make a dictionary that has named LINQ Expressions, since I cannot store the expressions in my database. I will store the name of the expression that is needed,开发者_运维技巧 and a structured IList<T> where T is a parameter type that can be stored in the database.

But it isn't quite working how I want ... I've got the following layout. This isn't a real expression, I'm just trying to get something to compile for now..

public static class Evaluations {
        public static Dictionary<string, Expression> Expressions = new Dictionary<string, Expression> {
            {
                "First Expression",
                new Expression<Func<int, int, int>> =
                    (current, next) => (current + next)
            }
        };
    }

However I am being told ... well, pretty much nothing. The compiler errors make no sense. Simply stating

This is not a variable

How can I add a System.Linq.Expressions.Expression as the Value of my IDictionary<string, Expression> safely? Any suggestions?


This isn't a valid expression:

new Expression<Func<int, int, int>> =
                (current, next) => (current + next)

What are you trying to assign a value to?

I think you mean:

(Expression<Func<int, int, int>>)((current, next) => current + next)

This compiles fine:

public static Dictionary<string, Expression> Expressions = 
    new Dictionary<string, Expression> {
    {
        "First Expression",
            (Expression<Func<int, int, int>>)((current, next) => current + next)
    }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消