Note that there are some explanatory texts on larger screens.

plurals
  1. POConcise Method for Passing Associative Arrays to Method
    primarykey
    data
    text
    <p>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:</p> <pre><code>public function tween(obj:DisplayObject, params:Object = null):void { if (params.ease != null) { //do something } //... } </code></pre> <p>And this could be called like:</p> <pre><code>tween(this, {ease:'out', duration:15}); </code></pre> <p>I'm looking for a way to do the same in C#. So far, I've gathered my options to be:</p> <p>a) creating a class or struct to define the possible param keys and types and pass that</p> <p>b) pass the parameters as generic type </p> <pre><code>tween(frameworkElement, new {ease = 'out', duration = 15}); </code></pre> <p>assuming</p> <pre><code>public static void tween(FrameworkElement target, object parameters); </code></pre> <p>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?)</p> <p>c) create a <code>Dictionary&lt;string, object&gt;</code> to pass the parameters into the tween function</p> <p>Any other ideas or sample code? I'm new to C#. </p> <p><strong>Edit</strong></p> <p>Took me all day to figure this out:</p> <p>"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."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload