2

I have a snippet that creates a method that starts something like this:

private $ReturnType$ $QueryName$($Param1Type$ $Param1Name$, $Param2Type$ $Param2Name$, $Param3Type$ $Param3Name$, $Param4Type$ $Param4Name$, $Param5Type$ $Param5Name$)

The names and types are used further on to create, cache and call a compiled Linq query.

If the query needs less than 5 parameters I need to remove the extras, if it needs more it's a pain to add them in everywhere.

Can I set up a snippet where the number of parameters can vary automatically.

2 Answers 2

2

how about having multiple snippets? I don't think it will be possible to have a dynamical number of parameters inside a snippet.

i personally would copy paste the exisiting snippet and edit and rename it once. Thats nothing you do all the time and if you miss something then its not that much work, to add that also by copying an existing snippet.

I think you would put more time and effort in finding a solution of the dynamical solution than just going the easy way.

Sign up to request clarification or add additional context in comments.

1 Comment

This looks like a sort of workable solution if nothing else presents itself.
-1

I don't really know how snippets work, but this is what I would do if I were to define such a method.

I would encapsulate paramType and paramName in a new Type:

public class ParameterDefinition {
     public Type Type { get; set; }
     public string Name { get; set; }
}

And then, I would define my method as follows:

public ReturnType QueryName(params ParameterDefinition[] parameters);

I hope it helps somehow.

2 Comments

This wouldn't work as the class you created couldn't be passed into a compiled linq query as I stated in my question. I think it would also add unnecessary complexity to the finished code.
Never said it would work. Hoped it would help you orientate on how to define such variable parameters. As I said, I never touched these snippets, but maybe you could have translated this code to the one you need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.