public static CodeTypeDeclaration AddDelegate <T>(this CodeTypeDeclaration classCode, string returnType, MemberAttributes ma, Expression <Func <T, string> > paramsAndName) { classCode.Members_Add(Define.Delegate(returnType, CorrectAttributes(classCode, ma), paramsAndName)); return(classCode); }
public void Builder_Delegate() { var c = new CodeDomGenerator(); c.AddNamespace("Samples").AddClass(Define.Class("TestClass") .AddDelegates( Define.Delegate(typeof(int), MemberAttributes.Public, (string s) => "xxx"), Define.Delegate(MemberAttributes.Public, (string s) => "xxx1"), Define.Delegate(typeof(string), MemberAttributes.Public, () => "xxx2") ) ); Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.CSharp)); Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.VB)); var ass = c.Compile(); Assert.IsNotNull(ass); Type TestClass = ass.GetType("Samples.TestClass"); Assert.IsNotNull(TestClass); }