Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public static MethodBodyReader Read(MethodBase method)
 {
     var reader = new MethodBodyReader(method);
     reader.ParseBody();
     return reader;
 }
Beispiel #4
0
 public ClassModelBuilder Method <T1, TReturn>(string name, Func <DynamicClassContext, T1, TReturn> body)
 {
     return(Method(name, new[] { typeof(T1) }, typeof(TReturn), MethodBodyReader.Read(body.Method)));
 }
Beispiel #5
0
 public ClassModelBuilder Method <TReturn>(string name, Func <DynamicClassContext, TReturn> body)
 {
     return(Method(name, Type.EmptyTypes, typeof(TReturn), MethodBodyReader.Read(body.Method)));
 }
Beispiel #6
0
 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)));
 }
Beispiel #7
0
 public ClassModelBuilder Constructor <T1>(Action <DynamicClassContext, T1> body)
 {
     return(Constructor(new[] { typeof(T1) }, typeof(void), MethodBodyReader.Read(body.Method)));
 }
Beispiel #8
0
 public ClassModelBuilder Constructor(Action <DynamicClassContext> body)
 {
     return(Constructor(Type.EmptyTypes, typeof(void), MethodBodyReader.Read(body.Method)));
 }
Beispiel #9
0
 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);
 }
Beispiel #10
0
 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)));
 }
Beispiel #11
0
 public ClassModelBuilder Method <T1>(string name, Action <DynamicClassContext, T1> body)
 {
     return(Method(name, new[] { typeof(T1) }, typeof(void), MethodBodyReader.Read(body.Method)));
 }
Beispiel #12
0
 public ClassModelBuilder Method(string name, Action <DynamicClassContext> body)
 {
     return(Method(name, Type.EmptyTypes, typeof(void), MethodBodyReader.Read(body.Method)));
 }