by

CSEmitter.cs

an "Event-Emitter" in C#.....     pretty kewel
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/662638/CSEmitter-cs?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; public class CSEmitter { public delegate void PropChangedHandler (object sender, EventArgs e = null); public event PropChangedHandler propChanged; public List<Delegate> subscibers = new List<Delegate>(); private bool pol = false; public bool Polarization { get { return pol; } set { if (pol != value) { pol = value; this.propChanged.Invoke(this.Polarization, new EventArgs()); } } } public CSEmitter ( ) { propChanged += CSEmitter_propChanged; } void CSEmitter_propChanged (object s, EventArgs e = null) { this.triggerAsync(s); } public PropChangedHandler create (Delegate callBack) { if (propChanged == null) { propChanged += CSEmitter_propChanged; } Subscribe(callBack); return propChanged; } void triggerAsync (object state) { foreach (Delegate d in subscibers) { d.DynamicInvoke(state); } } void Subscribe (Delegate callBk) { subscibers.Add(callBk); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus