Posted on 04/02/2020 09:50:17
Hi Hans,
Good question. Generally we try to not use extension methods, because they can be very difficult to find. But sometimes we have constraints that make it impractical to change everything in our API - like adding permission controllability to all objects in our application. When we DO add extension methods, we always try to add them to the same namespace that you use when you use the object that is the target of the extension.
Regarding your search, I think it's because we don't use stemming for our searches. Try with HasPermission (without the s) or GetPermission (again, without the s) and you should find them.
Here is a quick guide to ensure that most extensions you might want to use are available when you write a template:
When you use fx. Common.Context.Request you can do it like this:
int value = !string.IsNullOrEmpty(Common.Context.Request.QueryString["MyRequestInt"]) ? 0: Converter.ToInt32(Common.Context.Request.QueryString["MyRequestInt"]);
This can be split up a bit, resulting in you having more readable code, and as a bonus, discover all possible extension methods for IRequest (because you now have to be "using Dynamicweb.Environment" to compile the template).
IRequest request = Common.Context.Request;
int value = request.GetInt32("MyRequestInt")
The code is now cleaner and easier to maintain, and unless you've done it alot of times before, it's probably less error prone. So always split up the code into smaller pieces - it will even present extension methods relevant to your immidiate needs.
BR
Martin