public override void VisitParameterDefinitionCollection(ParameterDefinitionCollection parameters) { VisitCollection(parameters); }
public void VisitParameterDefinitionCollection(ParameterDefinitionCollection parameters) { }
/// <summary> /// Adds the given client-query to the list of queries /// </summary> /// <param parameterName="parameterExternalName">The parameterName to show to the end user</param> /// <param parameterName="table">The table descriptor that the query belongs to</param> /// <param parameterName="predicate">The predicate that defines the filter for the query</param> /// <param parameterName="parameterDefinitions">The parameter definitions defining the functionParameters to be used</param> private LiteQueryViewModel NewUserQuery(string externalName, FeatureTableDescriptor table, System.Linq.Expressions.Expression predicate, ParameterDefinitionCollection parameterDefinitions, bool addToQueries) { LiteQueryViewModel clientQuery = null; if (IsAuthenticated && Queries != null) { var predicateText = predicate != null?predicate.GeoLinqText(useInternalParameterNames : true) : null; var queryDefinition = new FeatureCollectionQueryDefinition() { ServiceProviderGroup = table.ServiceProviderGroup, Context = ServiceProviderDatumContext.User, Name = externalName.ToLower(), ExternalName = externalName, TableDescriptor = table, ParameterDefinitions = parameterDefinitions }; clientQuery = new LiteQueryViewModel(this.Messenger, queryDefinition, predicateText); if (addToQueries) { Queries.Add(clientQuery); SaveUserQueries(); } } return(clientQuery); }
private static void PopulateInterceptor(ToBeWeaved tbw, Instruction call, MethodReference targetMethod, MethodDefinition tplMethod) { EmittingContext ctx = new EmittingContext(tplMethod); VariableDefinition tmpObj = null; int offset = 0; // Interceptor signature must be : if (call.OpCode == OpCodes.Newobj) { // new object -> static ctorDeclaringType interceptor(ctorParametersList); tplMethod.ReturnType.ReturnType = targetMethod.DeclaringType; ctx.Emit(OpCodes.Ldnull); // create a brand new object, don't initialize an existing one } else if (Cil.IsStatic(targetMethod)) { // call static method -> static methodReturnType interceptor(methodParametersList); tplMethod.ReturnType.ReturnType = targetMethod.ReturnType.ReturnType; } else { //call instance method -> static methodReturnType interceptor(methodDeclaringType, methodParametersList); tplMethod.ReturnType.ReturnType = targetMethod.ReturnType.ReturnType; offset = 1; ctx.Emit(OpCodes.Ldarg_0); // load "this", which is the first parameter of the tplMethod if (!targetMethod.DeclaringType.IsValueType) { tplMethod.Parameters.Add(new ParameterDefinition(targetMethod.DeclaringType)); } else { tplMethod.Parameters.Add(new ParameterDefinition(new ReferenceType(targetMethod.DeclaringType))); ctx.Emit(OpCodes.Ldobj, targetMethod.DeclaringType); ctx.Emit(OpCodes.Box, targetMethod.DeclaringType); // Tmp object to store boxed value types when passed along call interceptors and then unwrapped after calls // tmpObj = new VariableDefinition(new ReferenceType(targetMethod.DeclaringType)); tmpObj = new VariableDefinition(Cil.GetTypeReference(typeof(object))); tplMethod.Body.Variables.Add(tmpObj); ctx.Emit(OpCodes.Stloc, tmpObj); ctx.Emit(OpCodes.Ldloc, tmpObj); } } foreach (ParameterDefinition p in targetMethod.Parameters) { tplMethod.Parameters.Add(new ParameterDefinition(p.ParameterType)); } ParameterDefinitionCollection tplParameters = tplMethod.Parameters; ParameterDefinitionCollection targetParameters = targetMethod.Parameters; int nbParams = tplParameters.Count - offset; if (nbParams == 0) { // Load an empty array ctx.Emit(OpCodes.Ldnull); } else { // Instantiate an array of the right size VariableDefinition arrayDef = new VariableDefinition(Cil.GetTypeReference(typeof(object[]))); tplMethod.Body.Variables.Add(arrayDef); ctx.Emit(OpCodes.Ldc_I4, nbParams); ctx.Emit(OpCodes.Newarr, Cil.GetTypeReference(typeof(object))); ctx.Emit(OpCodes.Stloc, arrayDef); // Load the array with data coming from the current parameters for (int i = tplParameters.Count - 1; i >= offset; i--) { ctx.Emit(OpCodes.Ldloc, arrayDef); ctx.Emit(OpCodes.Ldc_I4, i - offset); ParameterDefinition p = tplParameters[i]; ctx.Emit(OpCodes.Ldarg, p); Cil.BoxIfRequired(p.ParameterType, ctx); ctx.Emit(OpCodes.Stelem_Ref); } ctx.Emit(OpCodes.Ldloc, arrayDef); } // end of reify parameters Cil.InvokeInterceptors(tplMethod, ctx, targetMethod, tbw.Interceptors); if (call.OpCode != OpCodes.Newobj) { Cil.UnboxIfRequired(targetMethod.ReturnType.ReturnType, ctx); } if (call.OpCode != OpCodes.Newobj && !Cil.IsStatic(targetMethod) && targetMethod.DeclaringType.IsValueType) { ctx.Emit(OpCodes.Ldarg_0); ctx.Emit(OpCodes.Ldloc, tmpObj); ctx.Emit(OpCodes.Unbox, targetMethod.DeclaringType); ctx.Emit(OpCodes.Ldobj, targetMethod.DeclaringType); ctx.Emit(OpCodes.Stobj, targetMethod.DeclaringType); } // Cast (to satisfy PEVerify) Cil.CastIfRequired(tplMethod.ReturnType.ReturnType, ctx); ctx.Emit(OpCodes.Ret); }
public ParameterData(XmlDocument document, XmlNode parent, ParameterDefinitionCollection parameters) : base(document, parent) { this.parameters = parameters; }
public static bool IsEqual(this ParameterDefinitionCollection x, ParameterDefinitionCollection y) { return(x.IsEqual(y, true)); }
public void Cleanup() { foreach (DictionaryEntry entry in m_InterceptorsToWeave) { MethodDefinition containerMethod = entry.Key as MethodDefinition; TypeDefinition containerType = (TypeDefinition)containerMethod.DeclaringType; // Methods can be removed. In that case, they don't have a declaring type any more if (containerType != null) { // Clone and rename the target method MethodDefinition targetMethod = containerMethod.Clone(); targetMethod.Name += Joinpoints.OperationJoinPoint.WrappedMethodSuffix + "Body_" + Cil.GetNextId(); targetMethod.IsNewSlot = false; targetMethod.IsFinal = false; targetMethod.IsRuntimeSpecialName = targetMethod.IsSpecialName = false; containerType.Methods.Add(targetMethod); // Clear containerMethod containerMethod.Body.InitLocals = true; containerMethod.Body.ExceptionHandlers.Clear(); containerMethod.Body.Variables.Clear(); containerMethod.Body.Instructions.Clear(); // Reify arguments and call interceptors in the original (now target) method EmittingContext ctx = new EmittingContext(containerMethod); VariableDefinition tmpObj = null; if (!Cil.IsStatic(targetMethod)) { ctx.Emit(OpCodes.Ldarg_0); if (targetMethod.DeclaringType.IsValueType) { ctx.Emit(OpCodes.Ldobj, targetMethod.DeclaringType); ctx.Emit(OpCodes.Box, targetMethod.DeclaringType); // Tmp object to store boxed value types when passed along call interceptors and then unwrapped after calls //tmpObj = new VariableDefinition(new ReferenceType(targetMethod.DeclaringType)); tmpObj = new VariableDefinition(Cil.GetTypeReference(typeof(object))); containerMethod.Body.Variables.Add(tmpObj); ctx.Emit(OpCodes.Stloc, tmpObj); ctx.Emit(OpCodes.Ldloc, tmpObj); } } VariableDefinition arrayDef = new VariableDefinition(Cil.GetTypeReference(typeof(object[]))); containerMethod.Body.Variables.Add(arrayDef); ParameterDefinitionCollection containerParameters = containerMethod.Parameters; ParameterDefinitionCollection targetParameters = targetMethod.Parameters; // Instantiate an array of the right size ctx.Emit(OpCodes.Ldc_I4, containerParameters.Count); ctx.Emit(OpCodes.Newarr, Cil.GetTypeReference(typeof(object))); ctx.Emit(OpCodes.Stloc, arrayDef); // Load the array with data coming from the current parameters for (int i = containerParameters.Count - 1; i >= 0; i--) { ParameterDefinition p = containerParameters[i]; ctx.Emit(OpCodes.Ldloc, arrayDef); ctx.Emit(OpCodes.Ldc_I4, i); ctx.Emit(OpCodes.Ldarg, p); Cil.BoxIfRequired(p.ParameterType, ctx); ctx.Emit(OpCodes.Stelem_Ref); } // Pass real parameter values (taken from the stack) as the next parameter ctx.Emit(OpCodes.Ldloc, arrayDef); // end of Reify parameters ArrayList interceptors = entry.Value as ArrayList; Cil.InvokeInterceptors(containerMethod, ctx, targetMethod, interceptors); Cil.UnboxIfRequired(targetMethod.ReturnType.ReturnType, ctx); if (!Cil.IsStatic(targetMethod) && targetMethod.DeclaringType.IsValueType) { ctx.Emit(OpCodes.Ldarg_0); ctx.Emit(OpCodes.Ldloc, tmpObj); Cil.UnboxIfRequired(targetMethod.DeclaringType, ctx); ctx.Emit(OpCodes.Stobj, targetMethod.DeclaringType); } // Cast (to satisfy PEVerify) Cil.CastIfRequired(containerMethod.ReturnType.ReturnType, ctx); ctx.Emit(OpCodes.Ret); } } }
static IEnumerable <T> Select <T>(this ParameterDefinitionCollection source, Func <ParameterDefinition, T> selector) { return(source.Cast <ParameterDefinition>().Select(selector)); }
private void PatchMethod(MethodDefinition methodDef, TypeDefinition typeDef) { MethodReference refWritelnStr = _asmDef.MainModule.Import(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) })); MethodReference refWritelnInt = _asmDef.MainModule.Import(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(Int32) })); MethodReference refWritelnObj = _asmDef.MainModule.Import(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(object) })); MethodReference refBytetoString = _asmDef.MainModule.Import(typeof(BitConverter).GetMethod("ToString", new Type[] { typeof(byte[]) })); if (!methodDef.HasBody) { return; //check } MethodBody body = methodDef.Body; //new injector code to dump parameters ushort i = 0; int varCount = 0; int paramCount = 0; Instruction varMethodName = body.CilWorker.Create(OpCodes.Ldstr, "==========\n" + "*Type:" + typeDef.FullName + " method name:" + methodDef.Name); body.CilWorker.InsertBefore(methodDef.Body.Instructions[0], varMethodName); Instruction logMethodName = body.CilWorker.Create(OpCodes.Call, refWritelnStr); body.CilWorker.InsertAfter(varMethodName, logMethodName); if (methodDef.HasParameters) { ParameterDefinitionCollection passedParams = methodDef.Parameters; if (!methodDef.IsStatic) { paramCount = 1; } foreach (ParameterDefinition param in passedParams) { varCount = methodDef.Body.Variables.Count; i = System.Convert.ToUInt16(varCount); if (param.ParameterType.Name == "String" || param.ParameterType.Name == "Int32" || param.ParameterType.Name == "Byte[]") { TypeReference paramType = param.ParameterType; Instruction varParamName = body.CilWorker.Create(OpCodes.Ldstr, "*Param Name:" + param.Name); body.CilWorker.InsertAfter(logMethodName, varParamName); Instruction logParamName = body.CilWorker.Create(OpCodes.Call, refWritelnStr); body.CilWorker.InsertAfter(varParamName, logParamName); switch (param.ParameterType.Name) { case "String": Instruction varStrValue = body.CilWorker.Create(OpCodes.Ldarg, paramCount); body.CilWorker.InsertAfter(logParamName, varStrValue); Instruction logStr = body.CilWorker.Create(OpCodes.Call, refWritelnStr); body.CilWorker.InsertAfter(varStrValue, logStr); break; case "Int32": Instruction varIntValue = body.CilWorker.Create(OpCodes.Ldarg, paramCount); body.CilWorker.InsertAfter(logParamName, varIntValue); Instruction logInt = body.CilWorker.Create(OpCodes.Call, refWritelnInt); body.CilWorker.InsertAfter(varIntValue, logInt); break; case "Byte[]": Instruction varByteValue = body.CilWorker.Create(OpCodes.Ldarg, paramCount); body.CilWorker.InsertAfter(logParamName, varByteValue); Instruction toString = body.CilWorker.Create(OpCodes.Call, refBytetoString); body.CilWorker.InsertAfter(varByteValue, toString); Instruction logByte = body.CilWorker.Create(OpCodes.Call, refWritelnObj); body.CilWorker.InsertAfter(toString, logByte); break; default: break; } } paramCount++; } } }