어따 써먹을 지는 엿장수 맘대로지만 여튼 -_-.
namespace Ex
{
class MainClass
{
static void Main(string[] args)
{
TestClass t = new TestClass();
//TestDelegate del = () => { Console.WriteLine("Call delegate!!"); };
TestDelegate del = new TestDelegate(delMethod);
OtherDeleaget odel = () => { Console.WriteLine("Call OtherDeleaget!!"); };
ExistParamDelegate edel = (x) => { Console.WriteLine("Call ExistParamDelegate!! Value : " + x); };
ExistParamDelegate2 edel2 = (x, y) => { Console.WriteLine("Call ExistParamDelegate2!! Value : " + x + " Value2 : " + y); };
t.Func<TestDelegate>(del);
t.Func<OtherDeleaget>(odel);
t.Func<ExistParamDelegate>(edel, new object[]{"100"});
t.Func<ExistParamDelegate2>(edel2, new object[] { "100", "200" });
}
static void delMethod()
{
Console.WriteLine("Call delMathod!!");
}
}
delegate void TestDelegate();
delegate void OtherDeleaget();
delegate void ExistParamDelegate(string msg);
delegate void ExistParamDelegate2(string msg1, string msg2);
class TestClass
{
/*public void Func<T>(T t)
{
//((TestDelegate)(object)t)();
t.GetType().GetMethod("Invoke").Invoke(t, null);
}*/
public void Func<T>(T t, object[] args = null)
{
//((TestDelegate)(object)t)();
//object[] argss = new object[]{ };
t.GetType().GetMethod("Invoke").Invoke(t, args);
}
}
}
'C# 이야기' 카테고리의 다른 글
MVC - Views 폴더 하위에서 정적 컨텐츠 접근시 404 에러 (0) | 2015.08.04 |
---|---|
CallBack (0) | 2012.10.30 |
Entity Framework 4.X 사용자 정의 쿼리로 Entity Data Model 만들기. (0) | 2011.08.31 |
C# MVC3.(Razor) HTML 그대로 출력하기!와 왜~ 변환대는지 이유.. (0) | 2011.06.24 |
확장 메서드, Extension Method 개념 잡기!! (1) | 2010.12.15 |