Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 136425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:56:47+00:00 2026-05-11T06:56:47+00:00

Looking for a way to pass an associative array to a method. I’m looking

  • 0

Looking for a way to pass an associative array to a method. I’m looking to rewrite an Actionscript tween package in C# but running into trouble with ‘associative’ arrays/objects. Normally in Actionscript I might do something like:

public function tween(obj:DisplayObject, params:Object = null):void {     if (params.ease != null) {         //do something     }     //... } 

And this could be called like:

tween(this, {ease:'out', duration:15}); 

I’m looking for a way to do the same in C#. So far, I’ve gathered my options to be:

a) creating a class or struct to define the possible param keys and types and pass that

b) pass the parameters as generic type

tween(frameworkElement, new {ease = 'out', duration = 15}); 

assuming

public static void tween(FrameworkElement target, object parameters); 

and figure out some way to use that in the tween function (I’m not sure how to separate the key=value’s given that object. any ideas?)

c) create a Dictionary<string, object> to pass the parameters into the tween function

Any other ideas or sample code? I’m new to C#.

Edit

Took me all day to figure this out:

‘Anonymous types cannot be shared across assembly boundaries. The compiler ensures that there is at most one anonymous type for a given sequence of property name/type pairs within each assembly. To pass structures between assemblies you will need to properly define them.’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:56:47+00:00Added an answer on May 11, 2026 at 6:56 am

    EDIT: This is basically the mechanism that HtmlHelper extensions use in ASP.NET MVC. It’s not original with me.


    I’d favor a hybrid approach that has two different signatures. Note: I haven’t tried this and there may be a conflict between the two signatures so you may have to give the second method a slightly different name to allow the compiler to choose between them, but I don’t think so.

    public static void tween( FrameworkElement target, object parameters ) {     return tween( target, new ParameterDictionary( parameters ) ); }  public static void tween( FrameworkElement target,                           ParameterDictionary values ) {     if (values.ContainsKey( 'ease' ))     {       ....     } } 

    Then you have a ParameterDictionary class that uses reflection on the anonymous type and sets up the dictionary.

    public class ParameterDictionary : Dictionary<string,object> {     public ParameterDictionary( object parameters )     {          if (parameters != null)          {              foreach (PropertyInfo info in parameters.GetType()                                                      .GetProperties())              {                  object value = info.GetValue(parameters,null);                  this.Add(info.Name,value);              }          }     } } 

    This gives you both ease of use and ease of consumption — the ‘ugly’ reflection stuff is wrapped up in the single constructor for the dictionary rather than in your method. And, of course, the dictionary can be used over and over for similar purposes with the reflection code only written once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SQL Server uses memory efficiently and takes as much as… May 12, 2026 at 8:10 am
  • Editorial Team
    Editorial Team added an answer Theoretically elegant way of doing this: change the TwoDigitYearMax property… May 12, 2026 at 8:10 am
  • Editorial Team
    Editorial Team added an answer I'm almost certain that you need VS2008 SP1. The two… May 12, 2026 at 8:10 am

Related Questions

Looking for a way to pass an associative array to a method. I'm looking
I was looking for a way to stuff some data into a string across
I'm trying to pass table names to a sub that gets all the field
Short version: Is there a simple, built-in way to identify the calling view in
I program in PHP mostrly and Ruby sometimes I happen to be in need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.