Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing properties as parameters to be Got and Set
    primarykey
    data
    text
    <p>Well, I need to repeat same code for many properties. I've seen examples taking <code>Action</code> delegates, but they don't fit quite well here.</p> <p>I want something like this: (see explanation below)</p> <pre><code>Dictionary&lt;Property, object&gt; PropertyCorrectValues; public bool CheckValue(Property P) { return P.Value == PropertyCorrectValues[P]; } public void DoCorrection(Property P) { P.Value = PropertyCorrectValues[P]; } </code></pre> <p>.</p> <p>I want to have a dictionary containing many properties and their respective "correct" values. (I know it's not well declared, but that's the idea). Properties are not necessarely inside my class, some of them are in objects of different assemblies.</p> <p>A method <code>bool CheckValue(Property)</code>. This method must <code>access the actual value</code> of the property and <code>compare to the correct value</code>. </p> <p>And a method a <code>void DoCorrection(Property)</code>. This one <code>sets the property value</code> to the correct value.</p> <p>Remember I have many of those properties, I wouldn't like to call the methods by hand for each property. I'd rather iterate through the dicionary in a <code>foreach</code> statement.</p> <hr> <p>So, the main question is in the title.</p> <ul> <li><p>I've tried the <code>by ref</code>, but properties don't accept that.</p></li> <li><p>Am I obligated to use <code>reflection</code>??? Or is there another option (if I need, reflection answer will be accepted as well).</p></li> <li><p>Is there anyway I can make a dictionary with <code>pointers</code> in C#? Or some kind of assignment that <code>changes the value of variable's target</code> instead of <code>changing the target to another value</code>?</p></li> </ul> <p>Thanks for the help.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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