private Expression GetBaseInvokerExpression(MethodInfo method) { MethodInfo baseCallStub = CreateBaseCallStub(method); ConstructorInfo invokerCtor = typeof(BaseMethodInvoker).GetConstructor(new Type[] { typeof(object), typeof(IntPtr) }); Expression invokerExpression = new NewInstanceExpression(invokerCtor, SelfReference.Self.ToExpression(), new LoadFunctionExpression(baseCallStub)); return(invokerExpression); }
public void TypedMethodInvocationOnReferenceType() { var method = GetMethodEmitter(false, typeof(string), new Type[0]); Expression newObject = new NewInstanceExpression(typeof(ReferenceType), Type.EmptyTypes); ExpressionReference newObjectReference = new ExpressionReference(typeof(ReferenceType), newObject, method); method.ImplementByReturning(new TypedMethodInvocationExpression(newObjectReference, typeof(ReferenceType).GetMethod("Method"))); Assert.That(InvokeMethod(), Is.EqualTo("ReferenceTypeMethod")); }
public void TypedMethodInvocationMethodProperty() { var method = GetUnsavedMethodEmitter(false, typeof(string), new Type[0]); Expression newObject = new NewInstanceExpression(typeof(ReferenceType), Type.EmptyTypes); ExpressionReference newObjectReference = new ExpressionReference(typeof(ReferenceType), newObject, method); TypedMethodInvocationExpression expression = new TypedMethodInvocationExpression(newObjectReference, typeof(ReferenceType).GetMethod("Method")); Assert.That(expression.Method, Is.EqualTo(typeof(ReferenceType).GetMethod("Method"))); }
public void WriteInitialization(AbstractCodeBuilder codebuilder, Reference targetArgument, Reference mixinArray) { NewInstanceExpression expression = null; if (this.SourceArgIndex == EmptyIndex) { expression = new NewInstanceExpression(this.Callable, new Expression[] { targetArgument.ToExpression(), new MethodPointerExpression(this._callback) }); } else { expression = new NewInstanceExpression(this.Callable, new Expression[] { new LoadRefArrayElementExpression(this.SourceArgIndex, mixinArray), new MethodPointerExpression(this._callback) }); } codebuilder.AddStatement(new AssignStatement(this.Field, expression)); }
public void WriteInitialization(AbstractCodeBuilder codebuilder, Reference targetArgument, Reference mixinArray) { NewInstanceExpression newInst = null; if (SourceArgIndex == EmptyIndex) { newInst = new NewInstanceExpression(Callable, targetArgument.ToExpression(), new MethodPointerExpression(_callback)); } else { newInst = new NewInstanceExpression(Callable, new LoadRefArrayElementExpression(SourceArgIndex, mixinArray), new MethodPointerExpression(_callback)); } codebuilder.AddStatement(new AssignStatement( Field, newInst)); }
public void CustomAttributeExpression() { var methodEmitter = GetMethodEmitter(false, typeof(Tuple <SimpleAttribute, SimpleAttribute>), new Type[0]); LocalReference attributeOwner = methodEmitter.DeclareLocal(typeof(Type)); methodEmitter.AddStatement(new AssignStatement(attributeOwner, new TypeTokenExpression(typeof(ClassWithCustomAttribute)))); ConstructorInfo tupleCtor = typeof(Tuple <SimpleAttribute, SimpleAttribute>).GetConstructor(new[] { typeof(SimpleAttribute), typeof(SimpleAttribute) }); Expression tupleExpression = new NewInstanceExpression(tupleCtor, new CustomAttributeExpression(attributeOwner, typeof(SimpleAttribute), 0, true), new CustomAttributeExpression(attributeOwner, typeof(SimpleAttribute), 1, true)); methodEmitter.AddStatement(new ReturnStatement(tupleExpression)); object[] attributes = typeof(ClassWithCustomAttribute).GetCustomAttributes(typeof(SimpleAttribute), true); var attributeTuple = (Tuple <SimpleAttribute, SimpleAttribute>)InvokeMethod(); Assert.That(new object[] { attributeTuple.Item1, attributeTuple.Item2 }, Is.EquivalentTo(attributes)); }