Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to access EventArgs e value to use in HandleRequest
    text
    copied!<p>I am just learning about events, delegates and subscribers. I've spent the last 2 days researching and wrapping my brain around it all. I am unable to access the information being passed in my EventArgs e value. I have a saved project that wants to be opened. The state of the necessary forms are deserialized into a dictionary. A loop is hit that raises the UnpackRequest passing the key/value with it.</p> <p>ProjectManager.cs file:</p> <pre><code>public delegate void EventHandler&lt;TArgs&gt;(object sender, TArgs args) where TArgs : EventArgs; public event EventHandler&lt;UnpackEventArgs&gt; UnpackRequest; </code></pre> <p>Then farther down:</p> <p>ProjectManager.cs file:</p> <pre><code>//Raise a UnpackEvent //took out virtual protected void RaiseUnpackRequest(string key, object value) { if (UnpackRequest != null) //something has been added to the list? { UnpackEventArgs e = new UnpackEventArgs(key, value); UnpackRequest(this, e); } } </code></pre> <p>Then within the open method, after dictionary gets populated with states of each form:</p> <p>ProjectManager.cs file:</p> <pre><code>foreach (var pair in dictPackState) { string _key = pair.Key; dictUnpackedState[_key] = dictPackState[_key]; RaiseUnpackRequest(pair.Key, pair.Value); //raises the event. } </code></pre> <p>I have a class for the Event:</p> <pre><code>public class UnpackEventArgs : EventArgs { private string strKey; private object objValue; public UnpackEventArgs(string key, object value) { this.strKey = key; this.objValue = value; } //Public property to read the key/value ..and get them out public string Key { get { return strKey; } } public object Value { get { return objValue; } } } </code></pre> <p>I am still working on the code to add subscribers and how the project components get re-constituted in the individual forms. But the part I'm trying to work on now is in the MainForm.cs where I handle the Unpacked Request using the arguements getting passed. My e contains the key values and the key represents where to send the value (which is the form object).</p> <pre><code>private void HandleUnpackRequest(object sender, EventArgs e) { //reflection happens here. turn key into object //why can't i get e.key ??? object holder = e; //holder = VBTools.UnpackEventArgs key... value...all info //object goToUnpack = (e.key).GetType(); //goToUnpack.unpackState(e.value); } </code></pre> <p>I think I included all the necessary parts to get any help?! THANKS!</p>
 

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