public EasyMethod CreateSetMethod(MethodAttributes attrs, params Type[] parameters) { if (this._setMethod == null) { this._setMethod = new EasyMethod(this._maintype, "set_" + this._builder.Name, attrs, new ReturnReferenceExpression(typeof(void)), ArgumentsUtil.ConvertToArgumentReference(parameters)); } return(this._setMethod); }
public EasyMethod CreateRemoveOnMethod(MethodAttributes atts, params Type[] parameters) { if (this.m_removeOnMethod == null) { this.m_removeOnMethod = new EasyMethod(this.m_maintype, "remove_" + this.Name, atts, new ReturnReferenceExpression(typeof(void)), ArgumentsUtil.ConvertToArgumentReference(parameters)); } return(this.m_removeOnMethod); }
private void GenerateCall() { ArgumentReference arrayReference = new ArgumentReference(typeof(object[])); this._callmethod = base.CreateMethod("Call", new ReturnReferenceExpression(typeof(object)), new ArgumentReference[] { arrayReference }); TypeReference[] referenceArray = IndirectReference.WrapIfByRef(this._args); LocalReference[] referenceArray2 = new LocalReference[this._args.Length]; Expression[] args = new Expression[this._args.Length]; for (int i = 0; i < this._args.Length; i++) { if (this._args[i].Type.IsByRef) { referenceArray2[i] = this._callmethod.CodeBuilder.DeclareLocal(referenceArray[i].Type); this._callmethod.CodeBuilder.AddStatement(new AssignStatement(referenceArray2[i], new ConvertExpression(referenceArray[i].Type, new LoadRefArrayElementExpression(i, arrayReference)))); args[i] = referenceArray2[i].ToAddressOfExpression(); } else { args[i] = new ConvertExpression(referenceArray[i].Type, new LoadRefArrayElementExpression(i, arrayReference)); } } MethodInvocationExpression expression = new MethodInvocationExpression(this._invokeMethod, args); Expression instance = null; if (this._returnType.Type == typeof(void)) { this._callmethod.CodeBuilder.AddStatement(new ExpressionStatement(expression)); instance = NullExpression.Instance; } else { LocalReference target = this._callmethod.CodeBuilder.DeclareLocal(typeof(object)); this._callmethod.CodeBuilder.AddStatement(new AssignStatement(target, new ConvertExpression(typeof(object), this._returnType.Type, expression))); instance = target.ToExpression(); } for (int j = 0; j < this._args.Length; j++) { if (this._args[j].Type.IsByRef) { this._callmethod.CodeBuilder.AddStatement(new AssignArrayStatement(arrayReference, j, new ConvertExpression(typeof(object), referenceArray[j].Type, referenceArray2[j].ToExpression()))); } } this._callmethod.CodeBuilder.AddStatement(new ReturnStatement(instance)); }
protected virtual void ImplementCacheInvocationCache() { MethodInfo method = typeof(HybridDictionary).GetMethod("get_Item", new Type[] { typeof(object) }); MethodInfo info2 = typeof(HybridDictionary).GetMethod("Add", new Type[] { typeof(object), typeof(object) }); Type[] types = new Type[] { typeof(ICallable), typeof(object), typeof(MethodInfo), typeof(object) }; ArgumentReference reference = new ArgumentReference(typeof(ICallable)); ArgumentReference reference2 = new ArgumentReference(typeof(MethodInfo)); ArgumentReference reference3 = new ArgumentReference(typeof(object)); this._method2Invocation = this.MainTypeBuilder.CreateMethod("_Method2Invocation", new ReturnReferenceExpression(this.Context.Invocation), MethodAttributes.HideBySig | MethodAttributes.Family, new ArgumentReference[] { reference, reference2, reference3 }); LocalReference target = this._method2Invocation.CodeBuilder.DeclareLocal(this.Context.Invocation); LockBlockExpression expression = new LockBlockExpression(SelfReference.Self); expression.AddStatement(new AssignStatement(target, new ConvertExpression(this.Context.Invocation, new VirtualMethodInvocationExpression(this.CacheField, method, new Expression[] { reference2.ToExpression() })))); ConditionExpression expression2 = new ConditionExpression(OpCodes.Brfalse_S, target.ToExpression()); expression2.AddTrueStatement(new AssignStatement(target, new NewInstanceExpression(this.InvocationType.GetConstructor(types), new Expression[] { reference.ToExpression(), SelfReference.Self.ToExpression(), reference2.ToExpression(), reference3.ToExpression() }))); expression2.AddTrueStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(this.CacheField, info2, new Expression[] { reference2.ToExpression(), target.ToExpression() }))); expression.AddStatement(new ExpressionStatement(expression2)); this._method2Invocation.CodeBuilder.AddStatement(new ExpressionStatement(expression)); this._method2Invocation.CodeBuilder.AddStatement(new ReturnStatement(target)); }
public VirtualMethodInvocationExpression(Reference owner, EasyMethod method, params Expression[] args) : base(owner, method, args) { }
public VirtualMethodInvocationExpression(EasyMethod method, params Expression[] args) : base(method, args) { }
public void Add(EasyMethod method) { base.InnerList.Add(method); }
protected void GenerateMethodImplementation(MethodInfo method, EasyProperty[] properties) { if (!this.Context.ShouldSkip(method)) { ParameterInfo[] parameters = method.GetParameters(); Type[] args = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { args[i] = parameters[i].ParameterType; } MethodAttributes attrs = this.ObtainMethodAttributes(method); this.PreProcessMethod(method); EasyMethod builder = null; bool flag = method.IsSpecialName && method.Name.StartsWith("set_"); bool flag2 = method.IsSpecialName && method.Name.StartsWith("get_"); if (!flag && !flag2) { builder = this._typeBuilder.CreateMethod(method.Name, attrs, new ReturnReferenceExpression(method.ReturnType), args); } else if (flag || flag2) { foreach (EasyProperty property in properties) { if (property == null) { break; } if (property.Name.Equals(method.Name.Substring(4))) { if (property.IndexParameters != null) { bool flag3 = true; int length = parameters.Length; if (flag) { length--; } if (length != property.IndexParameters.Length) { continue; } for (int j = 0; j < property.IndexParameters.Length; j++) { if (property.IndexParameters[j].ParameterType != parameters[j].ParameterType) { flag3 = false; break; } } if (!flag3) { continue; } } if (flag) { builder = property.CreateSetMethod(attrs, args); } else { builder = property.CreateGetMethod(attrs, args); } break; } } } builder.DefineParameters(parameters); this.WriteInterceptorInvocationMethod(method, builder); this.PostProcessMethod(method); } }
public MethodInvocationExpression(Reference owner, EasyMethod method, params Expression[] args) : this(owner, method.MethodBuilder, args) { }
public MethodInvocationExpression(EasyMethod method, params Expression[] args) : this(SelfReference.Self, method.MethodBuilder, args) { }