/// <summary> /// Generates implementation for each method. /// </summary> /// <param name="method"></param> /// <param name="properties"></param> protected void GenerateMethodImplementation(MethodInfo method, EasyProperty[] properties) { if (Context.ShouldSkip(method)) { return; } ParameterInfo[] parametersInfo = method.GetParameters(); Type[] parameters = new Type[parametersInfo.Length]; for (int i = 0; i < parametersInfo.Length; i++) { parameters[i] = parametersInfo[i].ParameterType; } MethodAttributes atts = ObtainMethodAttributes(method); PreProcessMethod(method); EasyMethod easyMethod = null; bool isSetMethod = method.IsSpecialName && method.Name.StartsWith("set_"); bool isGetMethod = method.IsSpecialName && method.Name.StartsWith("get_"); if (!isSetMethod && !isGetMethod) { easyMethod = _typeBuilder.CreateMethod(method.Name, atts, new ReturnReferenceExpression(method.ReturnType), parameters); } else { if (isSetMethod || isGetMethod) { foreach (EasyProperty property in properties) { if (property == null) { break; } if (!property.Name.Equals(method.Name.Substring(4))) { continue; } if (property.IndexParameters != null) { bool signatureMatches = true; int numOfIndexes = parametersInfo.Length; //A set method already has a value parameter, and everything after //that is an indexer. if (isSetMethod) { numOfIndexes--; } if (numOfIndexes != property.IndexParameters.Length) { continue; } for (int i = 0; i < property.IndexParameters.Length; i++) { if (property.IndexParameters[i].ParameterType != parametersInfo[i].ParameterType) { signatureMatches = false; break; } } if (!signatureMatches) { continue; } } if (isSetMethod) { easyMethod = property.CreateSetMethod(atts, parameters); break; } else { easyMethod = property.CreateGetMethod(atts, parameters); break; } } } } easyMethod.DefineParameters(parametersInfo); WriteInterceptorInvocationMethod(method, easyMethod); PostProcessMethod(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.Name.StartsWith("set_"); bool flag2 = 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) { goto Label_015D; } for (int j = 0; j < property.IndexParameters.Length; j++) { if (property.IndexParameters[j].ParameterType != parameters[j].ParameterType) { flag3 = false; break; } } if (!flag3) { goto Label_015D; } } if (flag) { builder = property.CreateSetMethod(attrs, args); } else { builder = property.CreateGetMethod(attrs, args); } break; Label_015D :; } } } builder.DefineParameters(parameters); this.WriteInterceptorInvocationMethod(method, builder); this.PostProcessMethod(method); } }