Get value from anonymous type

后端 未结 4 1393
醉酒成梦
醉酒成梦 2021-02-12 15:08

I have a method as following:

public void MyMethod(object obj){

  // implement

}

And I call it like this:

MyMethod(new { mypa         


        
4条回答
  •  一整个雨季
    2021-02-12 15:45

    Everybody says "don't do it in the first place", but this is exactly what asp.mvc does! (Don't get me wrong I don't like it myself, but if you are writing custom html helpers you want to call them the way you call the normal html helpers...)

    And you can use asp.mvc to make your life easier:

    public void MyMethod(object obj){
      var dic=new System.Web.Routing.RouteValueDictionary(obj);
      string param=dic["myparam"] as string;
    }
    

提交回复
热议问题