delphimvcframework icon indicating copy to clipboard operation
delphimvcframework copied to clipboard

Feature Request: Multiple paths in MVCPath attribute constructor

Open fastbike opened this issue 5 years ago • 1 comments
trafficstars

I have a few controller actions where the only difference is the path.

So rather than

[MVCPath('path1')]
[MVCPath('path2')]
procedure Action1;

I'd like to do

[MVCPath('path1', 'path2')]
procedure Action1;

Is this syntactic sugar ? Maybe, but it would help to simplify the code and make it more readable.

fastbike avatar Oct 22 '20 02:10 fastbike

I've just started looking into an implementation. My first approach was to have a MVCPathAttribute constructor that took an array of strings. However this is not supported by the compiler (see https://stackoverflow.com/questions/27928740/attribute-constructor-with-array-parameter) constructor Create(const APaths: array of string); overload; // does not work

Another approach is to add a constructor that takes a character separated string of paths. The separator cannot be a valid URL character (see https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) so comma and semicolon are ruled out. A caret, although a little non intuitive, would work. It also does not break existing code. constructor Create(const APaths: string); overload; // caret separator

An alternative would be to include an optional separator. As well as not breaking existing code, this provides a prompt to the programmer as to what the default separator character is :+1: constructor Create(const APaths: string; ASeparator: char = '^');

fastbike avatar Aug 08 '21 01:08 fastbike

Done

danieleteti avatar Jan 30 '23 08:01 danieleteti