0

In mvc, you can pass arguments like so

  new { A = B, C= "D", E ="F", ... }

I'd like to pass arguments like so to my own procedures, looking for links to any samples/tutorial for the same

thanks

1
  • 2
    I don't understand the downvotes for this question. The author is clearly an inexperienced C# programmer, but the question is valid and makes sense! Commented Apr 15, 2012 at 15:47

3 Answers 3

2

It is object initialization check out this MSDN article

Sign up to request clarification or add additional context in comments.

Comments

1

You should look into anonymous types and reflection in C#.

In short:

  1. Your method will accept an object
  2. You use reflection to see get at the properties of the passed object.

Comments

0

If you're not using ASP.NET MVC then you'll need to use reflection in your method as stated in an answer above, but if you're writing an ASP.NET MVC extension method you can use HtmlHelper method called AnonymousObjectToHtmlAttributes which creates RouteValueDictionary from anonymous object or use RouteValueDictionary constructor that takes anonymous object to initialize its values.

1 Comment

Great, pointed me to the right direction from the answer by jpbochi here stackoverflow.com/questions/1619518/… since that answer is from 2010 was hoping to find something better using expando perhaps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.