public ClassModelBuilder Property(string name, Type type, Func <DynamicClassContext, object> getValue, Action <DynamicClassContext, object> setValue) { var get = getValue == null ? null : MethodBodyReader.Read(getValue.Method); var set = setValue == null ? null : MethodBodyReader.Read(setValue.Method); _properties.Add(new PropertyDeclaration { Name = name, Type = type, GetBody = get, SetBody = set }); return(this); }
public static void BuildFromExistingMethod(string newMethodName, MethodInfo originalMethod, TypeBuilder builder) { var tMethod = builder.DefineMethod(newMethodName, originalMethod.Attributes, originalMethod.CallingConvention, originalMethod.ReturnType, originalMethod.GetParameters().Select(p => p.ParameterType).ToArray()); var reader = MethodBodyReader.Read(originalMethod); MethodBodyBuilder bb = new MethodBodyBuilder(tMethod.GetILGenerator()); bb.DeclareLocals(reader.Locals.Select(l => l.LocalType)); bb.DeclareExceptionHandlers(reader.ExceptionHandlers); bb.EmitBody(reader.Instructions); }
public static MethodBodyReader Read(MethodBase method) { var reader = new MethodBodyReader(method); reader.ParseBody(); return reader; }
public ClassModelBuilder Method <T1, TReturn>(string name, Func <DynamicClassContext, T1, TReturn> body) { return(Method(name, new[] { typeof(T1) }, typeof(TReturn), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Method <TReturn>(string name, Func <DynamicClassContext, TReturn> body) { return(Method(name, Type.EmptyTypes, typeof(TReturn), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Constructor <T1, T2, T3, T4, T5, T6>(Action <DynamicClassContext, T1, T2, T3, T4, T5, T6> body) { return(Constructor(new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) }, typeof(void), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Constructor <T1>(Action <DynamicClassContext, T1> body) { return(Constructor(new[] { typeof(T1) }, typeof(void), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Constructor(Action <DynamicClassContext> body) { return(Constructor(Type.EmptyTypes, typeof(void), MethodBodyReader.Read(body.Method))); }
private ClassModelBuilder Method(string name, Type[] parameters, Type returnType, MethodBodyReader body) { _methods.Add(new MethodDeclaration() { Name = name, ParameterTypes = parameters, ReturnType = returnType, Body = body }); return(this); }
public ClassModelBuilder Method <T1, T2, T3, T4, T5, T6>(string name, Action <DynamicClassContext, T1, T2, T3, T4, T5, T6> body) { return(Method(name, new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) }, typeof(void), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Method <T1>(string name, Action <DynamicClassContext, T1> body) { return(Method(name, new[] { typeof(T1) }, typeof(void), MethodBodyReader.Read(body.Method))); }
public ClassModelBuilder Method(string name, Action <DynamicClassContext> body) { return(Method(name, Type.EmptyTypes, typeof(void), MethodBodyReader.Read(body.Method))); }