using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
namespace WConsoleDynamic
{
public class TestClassAttribute : Attribute
{
public TestClassAttribute()
{
DefaultDescription = "hello";
Console.WriteLine("I am here. I'm the attribute constructor!");
}
public String CustomDescription { get; set; }
public String DefaultDescription { get; set; }
public override String ToString()
{
return String.Format("Custom: {0}; Default: {1}", CustomDescription, DefaultDescription);
}
}
class DynObj : DynamicObject
{
GetMemberBinder saveOperation;
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
saveOperation = binder;
result = this;
return true;
}
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
Type myType = typeof(Program);
result = myType.GetMethod(saveOperation.Name).Invoke(null, args);
return true;
}
}
class BigObject
{
public int test = 9;
DynObj exec = new DynObj();
public dynamic Laun()
{
return exec;
}
}
class Program
{
static void Main(string[] args)
{
/*
dynamic d = new D1();
var attrs = Attribute.GetCustomAttributes(d.GetType());
foreach (var attr in attrs)
if (attr is TestClassAttribute)
Console.WriteLine(attr.ToString());
*/
dynamic d = new BigObject();
Console.WriteLine("{0} {1}", d,d.test);
d.Laun().func(1,3);
Console.ReadKey();
}
[TestClassAttribute]
public static void func(int a, int b)
{
Console.WriteLine("a={0} b={1}",a,b);
}
}
}