0

我使用此ActionLink方法来生成方法。

LinkExtensions.ActionLink Method (HtmlHelper, String, String, Object)

所以第四个参数是一个包含匿名属性的对象,用于路由。

可以将新的匿名属性自动附加/添加到现有的 routeValues 是 Object 吗?

如果是,如何?

假设我有一个方法:

public void Test( ref object currentRouteValues, string newValue)
{
    if(!string.IsNullOrEmpty(newValue)){
       // add a custom property here to currentRouteValues
       // something like: (is wrong but I don't know how to proceed)
       currentRouteValues = new { currentRouteValues, myCustoProperty = newValue };
    }
}

如何为上述方法自动执行此操作?

谢谢

4

1 回答 1

1

我想这会回答你的问题。

合并匿名类型

如果您只是想提取数据,它将是这样的。

        Object o = new { var1 = "the first var", var2 = "the second var" };

        System.Type type = o.GetType();

        foreach (var i in type.GetProperties())
        {
            Console.Write(i.GetValue(o));
        }

但是对于合并,请查看上面的链接。

于 2013-10-04T10:33:58.757 回答