Custom EventArgs

When passing any of the variables in the event, and the EventArgs because it is too lazy to inherit each time EventArgs so as to have an object inheritance versatility with a generic piece argument.

C # has learned almost by himself, if there is such a place that is incorrect if recognized, and you pointed out, please.

12/22 little bit I tried to change.

12/27 little bit I tried to change. Improved there was part of you pointed out.

The Atep starting from the class name Atep of the base class system, the newly discovered universal cellIt stands for function Arbitary-Triggered Eventhandler of Pluripotency. I thought the kana say even Step by Stupid-Triggered EventArgs of Pluripotency. Better yet, how about I Stap in Stimulus-Triggered Actions of Pluripotency?

Universal inherit short, the EventArgs with type arguments class cell I thing I have been a function of.

Next time, Masu me for a system that implements the task to the launcher in this application

Text

Basis function group

public class AtepEventArgs<T> : EventArgs
 {

public T Value { get; private set; }
public AtepEventArgs(T val)
{
Value = val;
} } public delegate void EventHandler<TSender, TEventArgs>(TSender sender, TEventArgs e); public interface ILauncher<T> {
event EventHandler<object, AtepEventArgs<T>> Raise; } public class AtepLauncher<T> : ILauncher<T> {
private T arg = default(T);
public AtepLauncher()
{
}
public AtepLauncher(T a)
{
this.arg = a;
}
public T Arg
{
get
{
return this.arg;
}
set
{
this.arg = value;
OnChanged(this, new AtepEventArgs<T>(this.arg));
}
}
//Delegate
public event EventHandler<object, AtepEventArgs<T>> Raise;
//Trigger
public void OnChanged(object sender, AtepEventArgs<T> e)
{
if (Raise != null)
{
//Call the Event
Raise(this, e);
}
} } public class AtepContainer<T> {
private List<ILauncher<T>> launcher;
public AtepContainer()
{
this.launcher = new List<ILauncher<T>>();
}

public void Add(ILauncher<T> lchr)
{
lchr.Raise += new EventHandler<object, AtepEventArgs<T>>(HandleChanged);
this.launcher.Add(lchr);
}

internal virtual void HandleChanged(object sender, AtepEventArgs<T> e)
{
//event firing, here describe the override method
Console.WriteLine("Received event. value={0}", e.Value);
} }

By purpose of the function

///<summary>
 ///(object) of type 
 ///</summary>
 public class MyItem
 {

public MyItem()
{
}
public MyItem(int n, string s)
{
Number = n;
TextMessage = s;
}

public int Number { get; set; }
public string TextMessage { get; set; } }

///<summary> ///(purpose) of the main ///</summary> internal class Test {
private static Test _instance { get; set; }
public static Test GetInstance()
{
return _instance;
}

private static void Main(string[] args)
{
var myLauncher = new AtepLauncher<MyItem>();

var container = new MyContainer();

container.Add(myLauncher);

myLauncher.Arg = new MyItem(1, "Item1");

//Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();

} }

The entire code

using System;
 using System.Collections.Generic;
 using System.Threading;

///<summary> ///Note : ///Atep = Arbitary-Triggered Eventhandler of Pluripotency ///</summary> namespace RaiseBaseClassEventsTestPart3 {
public class AtepEventArgs<T> : EventArgs
{
public T Value { get; private set; }
public AtepEventArgs(T val)
{
Value = val;
}
}
public delegate void EventHandler<TSender, TEventArgs>(TSender sender, TEventArgs e);
public interface ILauncher<T>
{
event EventHandler<object, AtepEventArgs<T>> Raise;
}
public class AtepLauncher<T> : ILauncher<T>
{
private T arg = default(T);
public AtepLauncher()
{
}
public AtepLauncher(T a)
{
this.arg = a;
}
public T Arg
{
get
{
return this.arg;
}
set
{
this.arg = value;
OnChanged(this, new AtepEventArgs<T>(this.arg));
}
}
//Delegate
public event EventHandler<object, AtepEventArgs<T>> Raise;
//Trigger
public void OnChanged(object sender, AtepEventArgs<T> e)
{
if (Raise != null)
{
//Call the Event
Raise(this, e);
}
}
}
public class AtepContainer<T>
{
private List<ILauncher<T>> launcher;
public AtepContainer()
{
this.launcher = new List<ILauncher<T>>();
}

public void Add(ILauncher<T> lchr)
{
lchr.Raise += new EventHandler<object, AtepEventArgs<T>>(HandleChanged);
this.launcher.Add(lchr);
}

internal virtual void HandleChanged(object sender, AtepEventArgs<T> e)
{
//event firing, here describe the override method
Console.WriteLine("Received event. value={0}", e.Value);
}
}

///<summary>
///(of purpose) launcher containers
///</summary>
public class MyContainer : AtepContainer<MyItem>
{
internal override void HandleChanged(object sender, AtepEventArgs<MyItem> e)
{
if (e.Value == null)
return;
var item = e.Value as MyItem;
var s = string.Format("({0}, {1})", item.Number.ToString(), item.TextMessage);
Console.WriteLine("Received event." + s);
}

}

///<summary>
///(object) of type
///</summary>
public class MyItem
{
public MyItem()
{
}
public MyItem(int n, string s)
{
Number = n;
TextMessage = s;
}

public int Number { get; set; }
public string TextMessage { get; set; }
}

///<summary>
///(purpose) of the main
///</summary>
internal class Test
{
private static Test _instance { get; set; }
public static Test GetInstance()
{
return _instance;
}

private static void Main(string[] args)
{
var myLauncher = new AtepLauncher<MyItem>();

var container = new MyContainer();

container.Add(myLauncher);

myLauncher.Arg = new MyItem(1, "Item1");

//Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();

}
}

}

reference