小编Ent*_*pin的帖子

使用Expression为对象赋值

我有这个使用Expression注入数据的注入器

    /// <summary>
    /// Inject a data to an instance of T
    /// </summary>
    /// <typeparam name="T">The type of object as parameter</typeparam>
    /// <param name="data">Object instance to where the data is injected</param>
    /// <param name="pairData">Set of data info</param>
    public static void InjectData<T>(this T data, Dictionary<Expression<Func<T, object>>, object> pairData) where T : IAuditable
    {
        // posible content of T data
        // Employee
        //      : Code
        //      : Name
        //      : ID

        // possible content of pairData
        // Key: a => a.Code …
Run Code Online (Sandbox Code Playgroud)

c# lambda expression

5
推荐指数
1
解决办法
1375
查看次数

标签 统计

c# ×1

expression ×1

lambda ×1